showModalWithKey<T> method

Future<T?> showModalWithKey<T>({
  1. required WidgetBuilder builder,
  2. bool barrierDismissible = true,
  3. Color? barrierColor = Colors.black54,
  4. String? barrierLabel,
  5. bool useSafeArea = true,
  6. bool useRootNavigator = true,
  7. RouteSettings? routeSettings,
  8. Offset? anchorPoint,
  9. TraversalEdgeBehavior? traversalEdgeBehavior,
  10. GlobalKey<NavigatorState>? navKey,
})

Implementation

Future<T?> showModalWithKey<T>({
  required WidgetBuilder builder,
  bool barrierDismissible = true,
  Color? barrierColor = Colors.black54,
  String? barrierLabel,
  bool useSafeArea = true,
  bool useRootNavigator = true,
  RouteSettings? routeSettings,
  Offset? anchorPoint,
  TraversalEdgeBehavior? traversalEdgeBehavior,
  GlobalKey<NavigatorState>? navKey,
}) {
  assert(
    useRootNavigator == true || navKey != null,
    "If useRootNavigator is false, a navKey must be provided.",
  );
  final navKey0 = useRootNavigator ? _navigatorKey : navKey!;

  if (navKey0.currentContext == null || navKey0.currentState == null) {
    return Future.value(null);
  }

  return navKey0.currentState!.push<T>(
    DialogRoute(
      context: navKey0.currentContext!,
      builder: builder,
      barrierColor: barrierColor,
      barrierDismissible: barrierDismissible,
      barrierLabel: barrierLabel,
      useSafeArea: useSafeArea,
      settings: routeSettings,
      anchorPoint: anchorPoint,
      traversalEdgeBehavior:
          traversalEdgeBehavior ?? TraversalEdgeBehavior.closedLoop,
    ),
  );
}