Skip to content

Instantly share code, notes, and snippets.

@saqib-github-commits
Created May 10, 2023 16:49
Show Gist options
  • Save saqib-github-commits/4e0844dda9a03568b4e571102de9ad71 to your computer and use it in GitHub Desktop.
Save saqib-github-commits/4e0844dda9a03568b4e571102de9ad71 to your computer and use it in GitHub Desktop.
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NetworkConnectivityScreen(
viewModel: NetworkConnectivityViewModel = viewModel(),
snackbarHostState: SnackbarHostState = SnackbarHostState()
) {
val networkStatus = viewModel.networkStatus.collectAsStateWithLifecycle()
if (networkStatus.value == NetworkStatus.Disconnected) {
LaunchedEffect(networkStatus) {
snackbarHostState.showSnackbar("you are offline")
}
}
Scaffold(
snackbarHost = { SnackbarHost(hostState = snackbarHostState) }
) { paddingValues ->
Box(
modifier = Modifier.fillMaxSize().padding(paddingValues),
contentAlignment = Alignment.Center
) {
Text(text = "Connectivity Service")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment