showSnackbar

suspend fun showSnackbar(message: String, actionLabel: String? = null, duration: SnackbarDuration = SnackbarDuration.Short): SnackbarResult

Shows or queues to be shown a Snackbar at the bottom of the Scaffold at which this state is attached and suspends until snackbar is disappeared.

SnackbarHostState guarantees to show at most one snackbar at a time. If this function is called while another snackbar is already visible, it will be suspended until this snack bar is shown and subsequently addressed. If the caller is cancelled, the snackbar will be removed from display and/or the queue to be displayed.

All of this allows for granular control over the snackbar queue from within:

Return

SnackbarResult.ActionPerformed if option action has been clicked or SnackbarResult.Dismissed if snackbar has been dismissed via timeout or by the user

Parameters

message

text to be shown in the Snackbar

actionLabel

optional action label to show as button in the Snackbar

duration

duration to control how long snackbar will be shown in SnackbarHost, either SnackbarDuration.Short, SnackbarDuration.Long or SnackbarDuration.Indefinite

Samples

androidx.compose.material.samples.ScaffoldWithCoroutinesSnackbar