Add Cloud Firestore to your Android apps built with Jetpack Compose

Overview

JetFirestore


Add Cloud Firestore to your Android apps built with Jetpack Compose

Now with Jetpack Compose you can easily add Cloud Firestore to your existing app with just a few lines of code.

To get started with JetFirestore just add the maven url and the dependency

build.gradle (Project level)

allprojects {
    repositories {
    ...
    //Add this url
    maven { url 'https://jitpack.io' }
    }
}

If you are using Android Studio Arctic Fox and do not have allProjects in build.gradle then add following maven url in settings.gradle like below

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        //Add this url
        maven { url 'https://jitpack.io' }
        jcenter() // Warning: this repository is going to shut down soon
    }
}

Once you have added the maven url now add the Stories dependency in the build.gradle (module level)

implementation 'com.github.raipankaj:JetFirestore:1.0.3'

Congratulations, you have successfully added the dependency. Now to get started with JetFirestore add the following code snippet

var booksList by remember { mutableStateOf(listOf<Books>()) }

JetFirestore(
    	path = { collection("books") },
	queryOnCollection = { orderBy("author", Query.Direction.DESCENDING) },
	onRealtimeCollectionFetch = { values,  exception ->
		booksList = values.getListOfObjects()
	}
) {
	Text(...)
}

Here are all the parameters accepted by JetFirestore composable.
@Composable
fun JetFirestore(
    path: FirebaseFirestore.() -> Any,
    limitOnSingleTimeCollectionFetch: Long = 0,
    queryOnCollection: (CollectionReference.() -> Query)? = null,
    onSingleTimeCollectionFetch: ((QuerySnapshot?, Exception?) -> Unit)? = null,
    onSingleTimeDocumentFetch: ((DocumentSnapshot?, Exception?) -> Unit)? = null,
    onRealtimeCollectionFetch: ((QuerySnapshot?, FirebaseFirestoreException?) -> Unit)? = null,
    onRealtimeDocumentFetch: ((DocumentSnapshot?, FirebaseFirestoreException?) -> Unit)? = null,
    content: @Composable (Pagination) -> Unit
)

Here is a code snippet to show list of documents based on pagination
@Composable
fun BooksInformation() {
    var booksList by remember { mutableStateOf(listOf<Books>()) }

    JetFirestore(
	path = { collection("books") },
	limitOnSingleTimeCollectionFetch = 2,
	queryOnCollection = { orderBy("cost", Query.Direction.DESCENDING) },
	onSingleTimeCollectionFetch = { values,  exception ->
	//When all documents are fetched
	//booksList = values.getListOfObjects()

	//When documents are fetched based on limit
	booksList = booksList + values.getListOfObjects()
	}
    ) { pagination ->
	Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.SpaceBetween) {
	    ListItem(booksList)
	    Row {
		Button(onClick = { pagination.loadNextPage() }, modifier = Modifier.fillMaxWidth()) {
		    Text("Next")
                }
            }
         }
    }
}

Note: If you like this library, then please hit the star button! 😃
You might also like...
A minimalist framework for rapidly building Jetpack compose apps.
A minimalist framework for rapidly building Jetpack compose apps.

VelocityX Show some ❤️ and star the repo. Subscribe to Codepur VelocityX is a 100% free Jetpack open-source minimalist UI Framework built with Kotlin

Explode compose elements on click! Just add explodeOnClick() modifier!
Explode compose elements on click! Just add explodeOnClick() modifier!

compose-explode Explode compose elements on click! Just add explodeOnClick() modifier! Inspired from ExplosionField Getting started Go to library/expl

Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.
Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

JetFlix - A clone of Android NetFlix app in Android built using Jetpack compose.
JetFlix - A clone of Android NetFlix app in Android built using Jetpack compose.

JetFlix A clone of Android NetFlix app in Android built using Jetpack compose. This sample app showcases the following: MVVM Architecture (ViewModel +

A 7 and 14 segment display for Android built with Jetpack Compose
A 7 and 14 segment display for Android built with Jetpack Compose

SegmentedDisplay A 7-segment and 14-segment display for Android build with Jetpack Compose Customizable Highly customisable. Hook up to a data stream

Morph is an Android library, written in Kotlin, built to work together with Jetpack Compose.
Morph is an Android library, written in Kotlin, built to work together with Jetpack Compose.

Morph Morph is an Android library, written in Kotlin, built to work together with Jetpack Compose. It allows you to transition any view to another vie

An Android / Wear OS app built with Jetpack Compose to search for definitions of English words
An Android / Wear OS app built with Jetpack Compose to search for definitions of English words

EnglishDictionary A simple Android / Wear OS app built with Jetpack Compose to s

ToDo-Task-App - An Android App built to demonstrate the use of Jetpack Compose, Material You, Room Database, and MVVM

ToDo Task App ToDo Task App is a sample Android app built with Jetpack Compose.

An android library to highlight different features of the app built using Jetpack Compose.
An android library to highlight different features of the app built using Jetpack Compose.

An android library to highlight different features of the app built using Jetpack Compose.

Comments
Releases(1.0.3)
Owner
Pankaj Rai
I am an android developer who likes to learn new technologies and bring ideas into reality for the betterment of a large community.
Pankaj Rai
Facebook clone built using Jetpack Compose, Firebase Authentication and Firebase Firestore.

facebook-compose Facebook clone built using Jetpack Compose, Firebase Authentication and Firebase Firestore. Setup Create a Firebase project and add t

Alex Styl 27 Dec 3, 2022
It's a simple app written in Kotlin that shows a simple solution for how to save an image into Firebase Storage, save the URL in Firestore, and read it back using Jetpack Compose.

It's a simple app written in Kotlin that shows a simple solution for how to save an image into Firebase Storage, save the URL in Firestore, and read it back using Jetpack Compose.

Alex 10 Dec 29, 2022
JetCam - Add camera capability to app built with Jetpack Compose

JetCam Add camera capability to your app with just a single method - JetCam To g

Pankaj Rai 6 Jul 8, 2022
This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Compose.

JetBMICalculator This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Co

BHAVNA THACKER 3 Dec 31, 2022
Jetpack-compose-uis - A collection of some UIs using Jetpack Compose. built using Katalog

Jetpack Compose UIs This is a collection of some UIs using Jetpack Compose. It i

Mori Atsushi 3 Dec 15, 2022
From Swedish "Öppettider", an app to quickly access your favorite places' opening times. Built to practice Android development and try out Jetpack Compose.

Appettider From Swedish "Öppettider", an app to quickly access your favorite places' opening times. Built to practice Android development and try out

Arianna Masciolini 0 Dec 6, 2021
FullMangement - an application that helps you manage your tasks effectively. built with the latest tachs like Compose UI, Jetpack libraries, and MVVM design pattern.

Full Management is an application that helps you manage your tasks effectively. built with the latest tachs like Compose UI, Jetpack libraries and MVVM design pattern.

Amr algnyat 4 Nov 1, 2022
📱 WhatsApp clone project demonstrates modern Android development built with Jetpack Compose and Stream Chat SDK for Compose.

This is a WhatsApp clone app built with Jetpack Compose and Stream Chat SDK for Compose. The purpose of this repository is to demonstrate below: Imple

Stream 689 Dec 25, 2022
A framework for building responsive Android apps using Jetpack Compose

Jetmagic - A framework for building responsive Android apps using Jetpack Compose Jetmagic is an Android framework that can be used to develop respons

Johann Blake 93 Dec 17, 2022
Some tips for developers who will involve Jetpack Compose in new APPs

Compose TakeAway 给即将用Jetpack Compose开发APP的开发人员 1. Jetpack Compose vs Xml Pros: 声明式UI,纯kotlin 代码更少 可直接兼容现有View - 双向兼容 性能更好(measure次数减少...) UI自定义更简单 没有a

Le 2 Mar 24, 2022