Skip to content

Instantly share code, notes, and snippets.

@igorescodro
Last active March 29, 2021 17:14
Show Gist options
  • Save igorescodro/024cf8a6f69bc622a8b32fdfcf6f5c31 to your computer and use it in GitHub Desktop.
Save igorescodro/024cf8a6f69bc622a8b32fdfcf6f5c31 to your computer and use it in GitHub Desktop.
@Composable
fun SnackbarSample() {
val snackbarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
val modifier = Modifier
Box(modifier.fillMaxSize()) {
Button(onClick = {
coroutineScope.launch {
snackbarHostState.showSnackbar(message = "This is a Snackbar")
}
}) {
Text(text = "Click me!")
}
SnackbarHost(
hostState = snackbarHostState,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment