dismissTopSheet static method
Dismisses the currently active top sheet
This method dismisses a top sheet (modal that slides in from the top). Top sheets use the bottom sheet controller internally with SheetPosition.top.
If an id is provided, will only dismiss if the active top sheet
matches that ID.
Example:
// Dismiss any active top sheet
Modal.dismissTopSheet();
// Dismiss specific top sheet by ID (recommended)
Modal.dismissTopSheet(id: 'notification_sheet');
Implementation
static Future<void> dismissTopSheet(
{String? id, VoidCallback? onDismissed}) async {
// Top sheets use the sheet controller
// Check if the active sheet is actually a top sheet (has sheetPosition top)
if (Modal.isSheetActive && !Modal.isSheetDismissing) {
final content = _sheetController.state;
final isTopSheet = content?.sheetPosition == SheetPosition.top;
if (!isTopSheet) {
if (_showDebugPrints) {
debugPrint(
'Modal.dismissTopSheet: Active bottom sheet is not a top sheet. Aborting.');
}
return;
}
// Call the unified dismiss method
await dismissBottomSheet(id: id, onDismissed: onDismissed);
} else {
if (_showDebugPrints) {
debugPrint(
'Modal.dismissTopSheet: No top sheet active or already dismissing');
}
}
}