I'm trying to display a snackbar in jetpack compose, but it is not displaying the right X close button present on the sample of the documentation. Instead, it's displaying just the message. I can't find how to display that X close button.
here you can see the supposed close button on the right:
my code:
val snackbarHostState = remember { SnackbarHostState() }
SnackbarHost(hostState = snackbarHostState)
uiState.toastMessage?.let {
val message = stringResource(it)
LaunchedEffect(key1 = message) {
snackbarHostState.showSnackbar(
message = message,
duration = SnackbarDuration.Indefinite
)
vm.toastMessage(null)
}
}
showSnackbar()
takes a withDismissAction
parameter. It defaults to false
. If you pass true
, it apparently adds the close option that you are seeking.