cupertinoMenuOpener<T> function

OpenMenu<T> cupertinoMenuOpener<T>({
  1. bool useScaffold = true,
})

Implementation

OpenMenu<T> cupertinoMenuOpener<T>({bool useScaffold = true}) {
  return <T>(
    BuildContext context, {
    required WidgetBuilder builder,
    bool displayDragHandle = true,
    bool dismissible = true,
    bool draggable = true,
    PathRouteSettings? settings,
    double? width,
    double? height,
    bool useRootNavigator = true,
    bool expand = false,
    bool nestModals = false,
    Constraints? constraints,
  }) {
    showCupertinoModalPopup(context: context, builder: builder);
    final scaffold = CupertinoScaffold.of(context);
    final nested = Provided.find<NestedNavigatorContainer>(context);
    if (nested?.child != null &&
        nestModals &&
        nested?.navigatorKey?.currentState != null) {
      return nested!.navigatorKey!.currentState!
          .push<T>(PlatformPageRoute(builder: builder));
    } else {
      final buildNested = (BuildContext context) {
        final parentNav = !nestModals
            ? null
            : Navigator.of(context, rootNavigator: useRootNavigator);
        final navKey = !nestModals
            ? null
            : GlobalKey<NavigatorState>(debugLabel: 'nestedNavKey');
        final nav = !nestModals
            ? null
            : Navigator(
                key: navKey,
                pages: [
                  CupertinoPage(
                      child: Builder(builder: builder), fullscreenDialog: true)
                ],
                onPopPage: (_, __) {
                  return false;
                },
              );

        final theWidget =
            (nestModals ? nav! : Builder(builder: builder)).maybeWrap(
          height != null,
          (child) => SizedBox(height: height!, child: child),
        );
        final widgetWithHandle =
            displayDragHandle ? theWidget.withDragHandle() : theWidget;

        return !nestModals
            ? widgetWithHandle
            : Provider(
                create: (_) => NestedNavigatorContainer(
                      child: nav,
                      parent: parentNav,
                      navigatorKey: navKey,
                    ),
                child: widgetWithHandle);
      };
      if (scaffold != null && useScaffold && useRootNavigator == true) {
        return CupertinoScaffold.showCupertinoModalBottomSheet<T>(
          context: context,
          useRootNavigator: useRootNavigator,
          bounce: true,
          backgroundColor: sunnyColors.modalBackground,
          enableDrag: draggable,
          expand: expand,
          settings: settings,
          isDismissible: dismissible,
          builder: (context) {
            Widget? w;
            return w ??= buildNested(context);
          },
        );
      } else {
        Widget? w;

        return showCupertinoModalBottomSheet<T>(
          context: context,
          bounce: true,
          expand: expand,
          enableDrag: draggable,
          backgroundColor: sunnyColors.modalBackground,
          useRootNavigator: useRootNavigator,
          settings: settings,
          barrierColor: Colors.black54,
          isDismissible: dismissible,
          builder: (context) {
            return w ??= buildNested(context);
          },
        );
      }
    }
  };
}