Im building a new Compose Multiplatform project and I want to add in some firestore functionality.
I added the Firebase Kotlin SDK: https://github.com/GitLiveApp/firebase-kotlin-sdk
# build.gradle.kts
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.googleServices)
kotlin("plugin.serialization") version "2.0.0-RC3"
}
kotlin {
sourceSets {
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
}
commonMain.dependencies {
implementation("dev.gitlive:firebase-firestore:1.12.0")
implementation("dev.gitlive:firebase-common:1.12.0")
}
}
}
But I can’t add any callback on my Firestore calls, like addSnapshotListener
or addOnSuccessListener
I get: Unresolved reference: addSnapshotListener
suspend fun getDocument(id: String) {
val db = Firebase.firestore
try {
val result = db.collection("session").document(id).get().addSnapshotListener { }
} catch (e: Exception) {
}
}
I would like to listen to changes in the data from the FireStore and update the UI when it happens.