show static method

void show({
  1. BuildContext? context,
  2. required ModalWidgetBuilder builder,
  3. String? id,
  4. ModalType modalType = ModalType.sheet,
  5. Alignment modalPosition = Alignment.bottomCenter,
  6. ModalAnimationType modalAnimationType = ModalAnimationType.fade,
  7. bool shouldBlurBackground = false,
  8. double blurAmount = 3.0,
  9. bool isDismissable = true,
  10. bool blockBackgroundInteraction = false,
  11. bool isDraggable = false,
  12. bool isExpandable = false,
  13. double? size,
  14. double expandedPercentageSize = 85,
  15. double contentPaddingByDragHandle = 35.0,
  16. bool isSwipeable = true,
  17. Duration? autoDismissDuration,
  18. SnackbarDisplayMode snackbarDisplayMode = SnackbarDisplayMode.staggered,
  19. int maxStackedSnackbars = 3,
  20. Color? backgroundColor,
  21. double? snackbarWidth,
  22. Color barrierColor = Colors.transparent,
  23. Offset? offset,
  24. SheetPosition? sheetPosition,
  25. Function? onDismissed,
  26. VoidCallback? onExpanded,
  27. VoidCallback? onTap,
})

Displays a modal on screen

This is the main entry point for showing modals in the application.

Parameters:

  • content: Optional ModalContent configuration 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);
}