-
@Stable() public final class SnackbarHostStateState of the SnackbarHost, controls the queue and the current Snackbar being shown inside the SnackbarHost.
This state usually lives as a part of a ScaffoldState and provided to the SnackbarHost automatically, but can be decoupled from it and live separately when desired.
-
-
Field Summary
Fields Modifier and Type Field Description private SnackbarDatacurrentSnackbarData
-
Constructor Summary
Constructors Constructor Description SnackbarHostState()
-
Method Summary
Modifier and Type Method Description final SnackbarDatagetCurrentSnackbarData()The current SnackbarData being shown by the SnackbarHost, of nullif none.final UnitsetCurrentSnackbarData(SnackbarData currentSnackbarData)final SnackbarResultshowSnackbar(String message, String actionLabel, SnackbarDuration duration)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. -
-
Method Detail
-
getCurrentSnackbarData
final SnackbarData getCurrentSnackbarData()
The current SnackbarData being shown by the SnackbarHost, of
nullif none.
-
setCurrentSnackbarData
final Unit setCurrentSnackbarData(SnackbarData currentSnackbarData)
-
showSnackbar
final SnackbarResult showSnackbar(String message, String actionLabel, SnackbarDuration duration)
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:
- Parameters:
message- text to be shown in the SnackbaractionLabel- optional action label to show as button in the Snackbarduration- duration to control how long snackbar will be shown in SnackbarHost, either SnackbarDuration.Short, SnackbarDuration.Long or SnackbarDuration.Indefinite
-
-
-
-