NullPointerException
NullPointerException

Reputation: 37721

Close button not appearing at SnackBar in Compose

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: enter image description here

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)
    }
}

Upvotes: 1

Views: 49

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007474

showSnackbar() takes a withDismissAction parameter. It defaults to false. If you pass true, it apparently adds the close option that you are seeking.

Upvotes: 3

Related Questions