showSafaeh<T> function

Future<T?> showSafaeh<T>({
  1. required BuildContext context,
  2. required Widget child,
  3. String? title,
  4. SafaehTitleBuilder? titleBuilder,
  5. Widget? tabletTopBarAction,
  6. double? maxWidth,
  7. double? maxHeight,
  8. bool useSafeArea = true,
  9. bool showDragHandle = true,
  10. bool enableDrag = true,
  11. ShapeBorder? sheetShape,
  12. bool barrierDismissible = true,
  13. EdgeInsetsGeometry? contentPadding,
  14. double? tabletBreakpoint,
  15. double? dialogMaxWidth,
  16. Duration? motion,
  17. Curve? enterCurve,
  18. Curve? exitCurve,
  19. double railWidthOf(
    1. BuildContext context
    )?,
  20. SafaehTransition? fadeScale,
  21. SafaehTransition? slideUp,
  22. SafaehPhoneSheetPlacement phonePlacement = SafaehPhoneSheetPlacement.bottom,
  23. T? dismissValue,
  24. bool useRootNavigator = true,
  25. String? dismissLabel,
  26. String? closeTooltip,
  27. bool paintPhoneTitle = true,
  28. SafaehFloatingAppearance? floatingAppearance,
  29. SafaehRouteOptions? route,
})

Shows child as a centered dialog on tablet+ and a bottom sheet on phone.

The same route morphs when the viewport crosses the tablet breakpoint.

Implementation

Future<T?> showSafaeh<T>({
  required BuildContext context,
  required Widget child,
  String? title,
  SafaehTitleBuilder? titleBuilder,
  Widget? tabletTopBarAction,
  double? maxWidth,
  double? maxHeight,
  bool useSafeArea = true,
  bool showDragHandle = true,
  bool enableDrag = true,
  ShapeBorder? sheetShape,
  bool barrierDismissible = true,
  EdgeInsetsGeometry? contentPadding,
  double? tabletBreakpoint,
  double? dialogMaxWidth,
  Duration? motion,
  Curve? enterCurve,
  Curve? exitCurve,
  double Function(BuildContext context)? railWidthOf,
  SafaehTransition? fadeScale,
  SafaehTransition? slideUp,
  SafaehPhoneSheetPlacement phonePlacement = SafaehPhoneSheetPlacement.bottom,
  T? dismissValue,
  bool useRootNavigator = true,
  String? dismissLabel,
  String? closeTooltip,
  bool paintPhoneTitle = true,
  SafaehFloatingAppearance? floatingAppearance,
  SafaehRouteOptions? route,
}) {
  final tokens = SafaehTheme.of(context);
  final resolvedRail = railWidthOf ?? route?.railWidthOf;
  final resolvedMaxWidth = maxWidth ?? route?.maxWidth;
  final resolvedMaxHeight = maxHeight ?? route?.maxHeight;
  final resolvedBarrier = route?.barrierDismissible ?? barrierDismissible;
  final resolvedMotion = safaehResolvedMotion(
    context,
    motion ?? route?.motion ?? tokens.motion,
  );
  final resolvedEnter = enterCurve ?? route?.enterCurve ?? tokens.enterCurve;
  final resolvedExit = exitCurve ?? route?.exitCurve ?? tokens.exitCurve;
  final resolvedFade = fadeScale ?? route?.fadeScale;
  final resolvedSlide = slideUp ?? route?.slideUp;
  final resolvedPlacement = route?.phonePlacement ?? phonePlacement;
  final resolvedRoot = route?.useRootNavigator ?? useRootNavigator;
  final resolvedBreakpoint = tabletBreakpoint ?? route?.tabletBreakpoint;
  final resolvedDismissLabel = dismissLabel ?? route?.dismissLabel;
  final resolvedCloseTooltip = closeTooltip ?? route?.closeTooltip;
  final resolvedFloatingAppearance =
      floatingAppearance ??
      route?.floatingAppearance ??
      tokens.floatingAppearance;
  final theme = Theme.of(context);

  return showGeneralDialog<T>(
    context: context,
    useRootNavigator: resolvedRoot,
    barrierDismissible: resolvedBarrier,
    barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
    barrierColor: theme.colorScheme.scrim.withValues(alpha: 0.32),
    transitionDuration: resolvedMotion,
    pageBuilder: (ctx, animation, secondaryAnimation) {
      return _AdaptiveSheetHost(
        title: title,
        titleBuilder: titleBuilder,
        tabletTopBarAction: tabletTopBarAction,
        maxWidth: resolvedMaxWidth,
        maxHeight: resolvedMaxHeight,
        useSafeArea: useSafeArea,
        showDragHandle: showDragHandle,
        enableDrag: enableDrag,
        sheetShape: sheetShape,
        barrierDismissible: resolvedBarrier,
        openAnimation: animation,
        contentPadding: contentPadding,
        tabletBreakpoint: resolvedBreakpoint ?? tokens.tabletBreakpoint,
        dialogMaxWidth: dialogMaxWidth ?? tokens.dialogMaxWidth,
        motion: resolvedMotion,
        enterCurve: resolvedEnter,
        exitCurve: resolvedExit,
        radius: tokens.radius,
        railWidthOf: resolvedRail,
        fadeScale: resolvedFade,
        slideUp: resolvedSlide,
        phonePlacement: resolvedPlacement,
        dismissValue: dismissValue,
        useRootNavigator: resolvedRoot,
        dismissLabel: resolvedDismissLabel,
        closeTooltip: resolvedCloseTooltip,
        paintPhoneTitle: paintPhoneTitle,
        floatingAppearance: resolvedFloatingAppearance,
        child: child,
      );
    },
    transitionBuilder: (ctx, animation, secondaryAnimation, child) => child,
  );
}