Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active Aug 18, 2021
Embed
What would you like to do?
@ExperimentalCoroutinesApi
@Composable
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