How to show snackbar in Jetpack Compose?

PHOTO EMBED

Mon Sep 20 2021 09:32:08 GMT+0000 (Coordinated Universal Time)

Saved by @GoodRequest. #kotlin

@Composable
fun SnackbarScreen() {
    val scope = rememberCoroutineScope()
    val snackbarHostState = remember { SnackbarHostState() }
    .
    .
    .
    FloatingActionButton(
        onClick = {
	    //Important part here
            scope.launch {
                snackbarHostState.showSnackbar("Hello there")
            }
	    //
        },
        content = { Icon(imageVector = Icons.Default.Add, contentDescription = "") }
    )
	
    SnackbarHost(hostState = snackbarHostState)
}
content_copyCOPY