I display a non dismissable dialog when the user lost connection. Somehow it’s not working correctly, sometimes the dialog shows up eventhough I’m connected to internet and doesnt want to diassapear.
The setup is super easy but still not working.
Code in thread
Aaron Waller
08/23/2022, 8:08 PM
Copy code
val connection by connectivityState()
val isConnected = connection === ConnectionState.Available
if (!isConnected) {
NoInternetDialog(context = context)
}
Copy code
@ExperimentalCoroutinesApi
@Composable
fun connectivityState(): State<ConnectionState> {
val context = LocalContext.current
return produceState(initialValue = context.currentConnectivityState) {
context.observeConnectivityAsFlow().collect { value = it }
}
}
l
Landry Norris
08/23/2022, 9:19 PM
Have you used a log to see if your connectivity library actually reported lost connection, or if this is some state not getting reset?
Landry Norris
08/23/2022, 9:20 PM
Also, have you tried Flow<T>.collectAsState() instead of produceState?