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,
})

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,
}) {
  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 = showDebugPrints;
  return _ActivatorWidget(
    borderRadius: borderRadius ?? BorderRadius.zero,
    shouldBounce: shouldBounceOnTap,
    backgroundColor: backgroundColor,
    child: child ?? const SizedBox.shrink(),
  );
}