show static method
void
show({
- BuildContext? context,
- required ModalWidgetBuilder builder,
- String? id,
- ModalType modalType = ModalType.sheet,
- Alignment modalPosition = Alignment.bottomCenter,
- ModalAnimationType modalAnimationType = ModalAnimationType.fade,
- bool shouldBlurBackground = false,
- double blurAmount = 3.0,
- bool isDismissable = true,
- bool blockBackgroundInteraction = false,
- bool isDraggable = false,
- bool isExpandable = false,
- double? size,
- double expandedPercentageSize = 85,
- double contentPaddingByDragHandle = 35.0,
- bool isSwipeable = true,
- Duration? autoDismissDuration,
- SnackbarDisplayMode snackbarDisplayMode = SnackbarDisplayMode.staggered,
- int maxStackedSnackbars = 3,
- Color? backgroundColor,
- double? snackbarWidth,
- Color barrierColor = Colors.transparent,
- Offset? offset,
- SheetPosition? sheetPosition,
- Function? onDismissed,
- VoidCallback? onExpanded,
- VoidCallback? onTap,
Displays a modal on screen
This is the main entry point for showing modals in the application.
Parameters:
content: OptionalModalContentconfiguration for the modal. If not provided, uses the default template.
Behavior:
- If no modal is currently active, shows the new modal
- If a modal is already active, replaces it with the new one
- Optimized to avoid unnecessary state changes
- Auto-update: If a modal with the same ID and type is already active, updates it instead of replacing
Example:
// Show a simple bottom sheet
Modal.show();
// Show a custom dialog
Modal.show(ModalContent(
widget: MyDialogContent(),
modalType: ModalType.dialog,
));
Displays a modal on screen with simplified API
This is the main entry point for showing modals in the application. All parameters from ModalContent are now available directly.
Example:
// Show a simple bottom sheet
Modal.show(
builder: ([_]) => Text('Hello!'),
);
// Show a dialog with custom styling
Modal.show(
builder: ([_]) => MyDialogContent(),
modalType: ModalType.dialog,
shouldBlurBackground: true,
blurAmount: 5.0,
);
// Show a side sheet
Modal.show(
builder: ([_]) => MySideMenu(),
modalType: ModalType.sideSheet,
sheetPosition: SheetPosition.right,
width: 300,
);
Implementation
/// Displays a modal on screen with simplified API
///
/// This is the main entry point for showing modals in the application.
/// All parameters from ModalContent are now available directly.
///
/// Example:
/// ```dart
/// // Show a simple bottom sheet
/// Modal.show(
/// builder: ([_]) => Text('Hello!'),
/// );
///
/// // Show a dialog with custom styling
/// Modal.show(
/// builder: ([_]) => MyDialogContent(),
/// modalType: ModalType.dialog,
/// shouldBlurBackground: true,
/// blurAmount: 5.0,
/// );
///
/// // Show a side sheet
/// Modal.show(
/// builder: ([_]) => MySideMenu(),
/// modalType: ModalType.sideSheet,
/// sheetPosition: SheetPosition.right,
/// width: 300,
/// );
/// ```
static void show({
BuildContext? context,
required ModalWidgetBuilder builder,
String? id,
ModalType modalType = ModalType.sheet,
Alignment modalPosition = Alignment.bottomCenter,
ModalAnimationType modalAnimationType = ModalAnimationType.fade,
bool shouldBlurBackground = false,
double blurAmount = 3.0,
bool isDismissable = true,
bool blockBackgroundInteraction = false,
bool isDraggable = false,
bool isExpandable = false,
double? size,
double expandedPercentageSize = 85,
double contentPaddingByDragHandle = 35.0,
bool isSwipeable = true,
Duration? autoDismissDuration,
SnackbarDisplayMode snackbarDisplayMode = SnackbarDisplayMode.staggered,
int maxStackedSnackbars = 3,
Color? backgroundColor,
double? snackbarWidth,
Color barrierColor = Colors.transparent,
Offset? offset,
SheetPosition? sheetPosition,
Function? onDismissed,
VoidCallback? onExpanded,
VoidCallback? onTap,
}) {
// Create internal ModalContent with all the parameters
final content = _ModalContent(
builder: builder,
id: id,
modalType: modalType,
modalPosition: modalPosition,
modalAnimationType: modalAnimationType,
shouldBlurBackground: shouldBlurBackground,
blurAmount: blurAmount,
isDismissable: isDismissable,
blockBackgroundInteraction: blockBackgroundInteraction,
isDraggable: isDraggable,
isExpandable: isExpandable,
size: size,
expandedPercentageSize: expandedPercentageSize,
contentPaddingByDragHandle: contentPaddingByDragHandle,
isSwipeable: isSwipeable,
autoDismissDuration: autoDismissDuration,
snackbarDisplayMode: snackbarDisplayMode,
maxStackedSnackbars: maxStackedSnackbars,
backgroundColor: backgroundColor,
snackbarWidth: snackbarWidth,
barrierColor: barrierColor,
offset: offset,
sheetPosition: sheetPosition,
onDismissed: onDismissed,
onExpanded: onExpanded,
onTap: onTap,
);
_showInternal(content, context: context);
}