appBuilder static method

Widget appBuilder(
  1. BuildContext context,
  2. Widget? child, {
  3. BorderRadius? borderRadius,
  4. bool shouldBounceOnTap = true,
  5. Color backgroundColor = Colors.black,
  6. bool showDebugPrints = false,
  7. ModalLifecycleCallback? onModalCreated,
  8. ModalLifecycleCallback? onModalDismissed,
  9. Set<ModalType>? lifecycleModalTypes,
  10. ModalLifecycleShouldNotify? shouldNotify,
})

Hook for MaterialApp.builder / WidgetsApp.builder.

This is the supported way to ensure _ActivatorWidget becomes a parent of your app's widget tree (no overlays, no runtime re-parenting).

Usage:

MaterialApp(
  builder: Modal.appBuilder,
  home: ...,
)

Implementation

static Widget appBuilder(
  /// The build context of the app
  BuildContext context,

  /// The child widget: the app background behind the modal
  Widget? child, {
  /// The border radius to apply to the modal's corners when [ModalType] is [ModalType.sheet] and when a sheet is active/showing
  BorderRadius? borderRadius,

  /// Whether the modal background should bounce when the dismiss barrier is tapped
  bool shouldBounceOnTap = true,

  /// The background color when [ModalType.sheet] sheet is active/showing, when the background layer is scaled
  Color backgroundColor = Colors.black,

  /// Whether to show debug prints for modal events
  bool showDebugPrints = false,

  /// Optional callback invoked whenever a modal is created.
  ModalLifecycleCallback? onModalCreated,

  /// Optional callback invoked whenever a modal is dismissed.
  ModalLifecycleCallback? onModalDismissed,

  /// Optional modal types to limit the lifecycle callbacks to.
  Set<ModalType>? lifecycleModalTypes,

  /// Optional predicate to decide whether a lifecycle event should be reported.
  ///
  /// If provided, it is evaluated alongside [lifecycleModalTypes]. Both must
  /// pass for the callback to run.
  ModalLifecycleShouldNotify? shouldNotify,
}) {
  // Install the modal activator and wire lifecycle callbacks.
  assert(
    child != null,
    'Modal.appBuilder requires the MaterialApp/WidgetsApp builder child. '
    'Make sure your app builder passes the provided child into Modal.appBuilder.',
  );

  _appBuilderInstalled = true;
  _showDebugPrints = false;
  _modalOverlayShouldBounceOnTap = shouldBounceOnTap;
  _appBuilderOnModalCreated = onModalCreated;
  _appBuilderOnModalDismissed = onModalDismissed;
  _appBuilderLifecycleModalTypes = lifecycleModalTypes == null
      ? null
      : Set<ModalType>.unmodifiable(lifecycleModalTypes);
  _appBuilderLifecycleShouldNotify = shouldNotify;
  return _ActivatorWidget(
    borderRadius: borderRadius ?? BorderRadius.zero,
    shouldBounce: shouldBounceOnTap,
    backgroundColor: backgroundColor,
    child: child ?? const SizedBox.shrink(),
  );
}