robnik
04/24/2021, 11:14 PMNavHost(...) { composable(..., arguments = ...) {
... inside that I extract at argument (id: String), now I can want to query my Room database, like db.getThing(id):Flow<Thing>
and pass it to a @Composable fun ThingView(thing)
but that DB function is not callable outside of a coroutine context. So... where do I get the coroutine context, and then how to I hook the result obtained within that back to some MutableState that Compose can observe, in ThingView.Ian Lake
04/24/2021, 11:26 PMFlow<Thing>
should not be suspend
methods, so you just call it directly and call collectAsState()
on the Flow as per https://developer.android.com/jetpack/compose/libraries#streamsrobnik
04/25/2021, 12:02 AMval state by flow.collectAsState(initial=null)
so there's an extra assignment to a local. But maybe that's just reality. The UI does need to wait for a DB query. It's just that the docs tend to use simpler examples.robnik
04/25/2021, 12:03 AMIan Lake
04/25/2021, 12:06 AMdewildte
04/25/2021, 1:25 AM