I display a non dismissable dialog when the user l...
# compose
a
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
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
Have you used a log to see if your connectivity library actually reported lost connection, or if this is some state not getting reset?
Also, have you tried Flow<T>.collectAsState() instead of produceState?
d
===
instead of
==
?