dismissAllSnackbars static method
void
dismissAllSnackbars()
Dismisses all snackbars while preserving other active modals
Clears the snackbar queue without affecting dialogs or bottom sheets. This is the key benefit of the type-specific controller architecture - snackbar dismissal is completely independent from other modal types.
Example:
Modal.dismissAllSnackbars();
Implementation
static void dismissAllSnackbars() {
final currentQueue = _snackbarQueueNotifier.state;
if (currentQueue.isNotEmpty) {
// CAPTURE IDs of all snackbars being dismissed for tracking
final dismissedIds = <String>[];
for (final position in currentQueue.keys) {
for (final snackbar in currentQueue[position]!) {
dismissedIds.add(snackbar.uniqueId);
}
}
if (_showDebugPrints) {
debugPrint(
'Modal.dismissAllSnackbars: dismissing ${dismissedIds.length} snackbars: $dismissedIds');
}
// Unregister all snackbars from registry
_unregisterModals(dismissedIds);
_snackbarQueueNotifier.state = {};
_snackbarStackIndexNotifier.state = 0;
_snackbarController.refresh();
_clearAllSnackbarDismissing();
_staggeredExpandedNotifier.state = null;
// If only snackbars were visible (no dialog/bottomsheet), also clear active modal controller
if (Modal.controller.state?.modalType == ModalType.snackbar) {
Modal.controller.refresh();
}
if (_showDebugPrints) {
debugPrint(
'Modal.dismissAllSnackbars: completed dismissing IDs: $dismissedIds');
}
}
}