Firestore Query Get Single Result With Coroutines Flow (Kotlin)

August 19, 2019
fun isRecordFound(): Flow<Boolean> {
    val query = ...

    return flow {
        val docs = query.get().await()
        emit(docs.isEmpty)
    }
}
launch(Dispatchers.Default) {
    if (isRecordFound().single()) {
        // do something
    }
}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.