Skip to content

Instantly share code, notes, and snippets.

Last active Aug 18, 2021
What would you like to do?
fun connectivityState(): State<ConnectionState> {
val context = LocalContext.current
// Creates a State<ConnectionState> with current connectivity state as initial value
return produceState(initialValue = context.currentConnectivityState) {
// In a coroutine, can make suspend calls
context.observeConnectivityAsFlow().collect { value = it }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment