В настоящее время я использую его в своем приложении следующим образом:
UI:
Код: Выделить всё
usersViewModel.userInfo.collectAsState(null).apply {
//use data from userInfo
}
Код: Выделить всё
val userInfo = repo.getUserProfile().catch { println("no User found") }
Код: Выделить всё
fun getUserProfile(): Flow = flow {
try {
firestore.collection("User").document(auth.currentUser!!.uid).snapshots.collect { user ->
emit(user.data())
}
}catch (ex: Exception){
println("Something wrong")
}
}
fun getAllRestaurants(): Flow {
val user = getUserProfile()
firestore.collection("Restaurant").snapshots.map { querySnapshot ->
val restaurants = querySnapshot.documents.map { documentSnapshot ->
documentSnapshot.data()
}.filter { restaurant ->
checkIfPointInsidePolygon(user.first()!!.userLocation!!, restaurant.polygonList)
}
restaurants
}
}
Спасибо за помощь!
Подробнее здесь: https://stackoverflow.com/questions/792 ... rhitecture