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

<div class="highlight highlight-source-kotlin position-relative" data-snippet-clipboard-copy-content="
var booksList by remember { mutableStateOf(listOf()) }

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

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

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