-
-
Save PatilShreyas/1c996240c3bbf492d848ffa55b351b7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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