Snackbar Controller
object SnackbarController
A controller for managing snackbar events.
This object provides a centralized way to send and receive snackbar events, allowing different parts of the application to trigger snackbar notifications.
Snackbars are displayed using a SnackbarHostState which should collect the events flow.
Example usage:
// In your Composable
val snackbarHostState = remember { SnackbarHostState() }
LaunchedEffect(Unit) {
SnackbarController.events.collect { event ->
snackbarHostState.showSnackbar(
message = event.message,
actionLabel = event.actionLabel,
duration = event.duration
)
}
}
// To show a snackbar from anywhere
CoroutineScope(Dispatchers.Main).launch {
SnackbarController.sendEvent(
SnackbarEvent(message = "Hello Snackbar!")
)
}Content copied to clipboard
Functions
Link copied to clipboard
Sends a SnackbarEvent to be displayed. This function is suspending and should be called from a coroutine.