dismissDialog method

void dismissDialog(
  1. BuildContext context
)

Dismisses the currently displayed dialog.

This method removes the top-most dialog from the navigation stack, effectively hiding any currently displayed dialog including loading dialogs shown by showLoader.

Parameters:

  • context - The build context for navigation

Dismissal Behavior

  • Top Dialog: Removes the most recently shown dialog
  • Navigation Stack: Properly manages the navigation stack
  • Context Safety: Works with any valid build context
  • Immediate Effect: Dialog is dismissed immediately when called

Usage

// Dismiss loading dialog after operation completes
dismissDialog(context);

// Or use in error handling
try {
  await operation();
} catch (e) {
  // Handle error
} finally {
  dismissDialog(context); // Always dismiss
}

Uses Navigator.pop to:

  • Remove the top route from the navigation stack
  • Handle any dialog-specific cleanup
  • Maintain proper navigation state
  • Support back button navigation

Safety Considerations

  • Only call this method when a dialog is actually displayed
  • Use the same context that was used to show the dialog
  • Consider using try-finally blocks for automatic cleanup
  • Handle cases where no dialog is currently shown

Implementation

void dismissDialog(BuildContext context) {
  Navigator.pop(context);
}