Mjahangiry75
08/11/2021, 1:25 PM@Composable
fun networkState(): State<Boolean> {
val context = LocalContext.current
return context.networkStateFlow().collectAsState(initial = false)
}
Actually I'm trying to observe the network state in composablesAdam Powell
08/11/2021, 1:28 PMcontext.nextworkStateFlow()
returns a new flow instance each time (and since it looks like an extension function it probably does) you'll want to write that as
val context = LocalContext.current
return remember(context) { context.networkStateFlow() }.collectAsState(false)
Mjahangiry75
08/11/2021, 1:32 PMremember
takes context
as a parameter?Adam Powell
08/11/2021, 1:37 PMLocalContext
changes you want to get a new flow for the new context. In practice you probably won't actually see this ever change. But you will see this function recompose from its caller, so you do want to remember the flow.Mjahangiry75
08/11/2021, 1:47 PM