Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active August 18, 2021 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatilShreyas/1c996240c3bbf492d848ffa55b351b7c to your computer and use it in GitHub Desktop.
Save PatilShreyas/1c996240c3bbf492d848ffa55b351b7c to your computer and use it in GitHub Desktop.
@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