open<T> method

  1. @override
Future<T?> open<T>(
  1. BuildContext context, {
  2. required WidgetBuilder builder,
  3. bool displayDragHandle = true,
  4. bool dismissible = true,
  5. bool draggable = true,
  6. PathRouteSettings? settings,
  7. double? width,
  8. double? height,
  9. bool useRootNavigator = true,
  10. bool expand = false,
  11. bool nestModals = false,
  12. Constraints? constraints,
  13. dynamic extraOptions,
})
override

Implementation

@override
Future<T?> open<T>(
  BuildContext context, {
  required 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,
  extraOptions,
}) {
  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);
        },
      );
    }
  }
}