dismissAll static method
Dismisses all active modals of all types immediately
This method immediately clears all dialogs, bottom sheets, and snackbars without animations. Use this when you need to reset the modal state completely, such as before showing a new set of modals.
For animated dismissal of specific modals, use the type-specific methods:
- dismissDialog for dialogs
- dismissBottomSheet for bottom sheets
- dismissById for any modal by ID
Parameters:
onDismissed: Optional callback executed after all modals are dismissed
Example:
// Dismiss everything immediately
Modal.dismissAll();
// Dismiss everything with callback
Modal.dismissAll(onDismissed: () => print('All modals dismissed'));
Implementation
static void dismissAll({VoidCallback? onDismissed}) {
if (_showDebugPrints) {
debugPrint('Modal.dismissAll: dismissing all modals');
}
// Web/engine safety: Avoid mutating the overlay/widget tree in the middle of
// a frame/scheduler callback. This prevents rare "Trying to render a disposed
// EngineFlutterView" assertions when dismissAll is triggered during a draw.
if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.idle) {
SchedulerBinding.instance.addPostFrameCallback((_) {
dismissAll(onDismissed: onDismissed);
});
return;
}
// Immediate reset - clear all controllers without animations
_snackbarQueueNotifier.state = {};
_snackbarController.refresh();
_clearAllSnackbarDismissing();
_snackbarStackIndexNotifier.state = 0;
_staggeredExpandedNotifier.state = null;
// Explicitly cancel any pending timers to prevent leaks and test failures
_backgroundAnimationTimer?.cancel();
_backgroundAnimationTimer = null;
_snackbarRetryTimer?.cancel();
_snackbarRetryTimer = null;
_dialogController.refresh();
_dialogDismissingNotifier.state = false;
_sheetController.refresh();
_sheetDismissingNotifier.state = false;
_resetHeightCallback?.call();
_modalSheetHeightNotifier.state = 0.0;
_modalDragOffsetNotifier.state = 0.0;
_activeModalController.refresh();
_dismissModalAnimationController.state = false;
_backgroundLayerAnimationNotifier.state = 0.0;
_blurAnimationStateNotifier.state = 0.0;
// Clear the entire modal registry
_modalRegistry.state = {};
Modal.isDismissing = false;
onDismissed?.call();
// debugPrint('Modal.dismissAll: completed');
}