show<T> static method

Future<T?> show<T>({
  1. required BuildContext context,
  2. required WidgetBuilder builder,
  3. double halfSize = 0.45,
  4. double? fullSize,
  5. GlassSheetState initialState = GlassSheetState.half,
  6. double fillThreshold = 0.60,
  7. LiquidGlassSettings? settings,
  8. Color? expandedColor,
  9. ValueChanged<GlassSheetState>? onStateChanged,
  10. GlassSheetMode mode = GlassSheetMode.dismissible,
  11. double peekSize = 90.0,
  12. GlassQuality? quality,
  13. bool platformViewBackdrop = false,
  14. Color barrierColor = GlassDefaults.barrierColor,
  15. bool isDismissible = true,
  16. bool useRootNavigator = false,
  17. double interactionScale = 1.01,
  18. bool enableInteractionGlow = true,
  19. bool enableSaturationGlow = true,
  20. LiquidGlassSettings? peekSettings,
  21. LiquidGlassSettings? halfSettings,
  22. LiquidGlassSettings? fullSettings,
  23. double stretch = 0.5,
  24. GlassModalSheetController? controller,
  25. GlassFillTransition fillTransition = GlassFillTransition.instant,
  26. bool showDragIndicator = true,
  27. Color? dragIndicatorColor,
  28. double dragIndicatorWidth = 36,
  29. double? topBorderRadius = 56,
  30. double? bottomBorderRadius,
  31. double? fullTopBorderRadius = 46,
  32. double? fullBottomBorderRadius,
  33. double horizontalMargin = 8.0,
  34. double bottomMargin = 8.0,
  35. double resistance = 0.08,
  36. double snapThreshold = 0.4,
  37. double velocityThreshold = 700.0,
  38. Color? glowColor,
  39. double glowRadius = 1.5,
  40. bool suppressInteractionOnChildren = false,
  41. EdgeInsetsGeometry? padding,
  42. bool enableTopFade = false,
  43. double topFadeHeight = 40.0,
  44. bool maintainContentGlass = true,
  45. LiquidGlassSettings? fullStateContentSettings,
  46. Set<GlassSheetDetent> detents = const {GlassSheetDetent.medium, GlassSheetDetent.large},
  47. bool dismissible = true,
  48. bool? enablePeek,
  49. double? peekHorizontalMargin,
  50. double? peekBottomMargin,
  51. double? peekWidth,
  52. double? peekTopBorderRadius,
  53. double? peekBottomRadius,
})

Shows a high-fidelity glass modal sheet.

Implementation

static Future<T?> show<T>({
  required BuildContext context,
  required WidgetBuilder builder,
  double halfSize = 0.45,
  double? fullSize,
  GlassSheetState initialState = GlassSheetState.half,
  double fillThreshold = 0.60,
  LiquidGlassSettings? settings,
  Color? expandedColor,
  ValueChanged<GlassSheetState>? onStateChanged,
  GlassSheetMode mode = GlassSheetMode.dismissible,
  double peekSize = 90.0,
  GlassQuality? quality,
  bool platformViewBackdrop = false,
  Color barrierColor = GlassDefaults.barrierColor,
  bool isDismissible = true,
  bool useRootNavigator = false,
  double interactionScale = 1.01,
  bool enableInteractionGlow = true,
  bool enableSaturationGlow = true,
  LiquidGlassSettings? peekSettings,
  LiquidGlassSettings? halfSettings,
  LiquidGlassSettings? fullSettings,
  double stretch = 0.5,
  GlassModalSheetController? controller,
  GlassFillTransition fillTransition = GlassFillTransition.instant,
  bool showDragIndicator = true,
  Color? dragIndicatorColor,
  double dragIndicatorWidth = 36,
  double? topBorderRadius = 56,
  double? bottomBorderRadius,
  double? fullTopBorderRadius = 46,
  double? fullBottomBorderRadius,
  double horizontalMargin = 8.0,
  double bottomMargin = 8.0,
  double resistance = 0.08,
  double snapThreshold = 0.4,
  double velocityThreshold = 700.0,
  Color? glowColor,
  double glowRadius = 1.5,
  bool suppressInteractionOnChildren = false,
  EdgeInsetsGeometry? padding,
  bool enableTopFade = false,
  double topFadeHeight = 40.0,
  bool maintainContentGlass = true,
  LiquidGlassSettings? fullStateContentSettings,
  Set<GlassSheetDetent> detents = const {
    GlassSheetDetent.medium,
    GlassSheetDetent.large
  },
  bool dismissible = true,
  bool? enablePeek,
  double? peekHorizontalMargin,
  double? peekBottomMargin,
  double? peekWidth,
  double? peekTopBorderRadius,
  double? peekBottomRadius,
}) {
  assert(
      detents.isNotEmpty,
      'GlassModalSheet.show() needs at least one detent — add medium '
      'and/or large (small alone is a floor, not a resting height).');
  assert(() {
    if (mode == GlassSheetMode.persistent &&
        barrierColor == const Color(0x00000000)) {
      debugPrint(
        '[GlassModalSheet] WARNING: show() with persistent mode and '
        'transparent barrier does NOT provide true hit-through interaction. '
        'Use GlassModalSheetScaffold directly for maps-style hit-through UI.',
      );
    }
    return true;
  }());

  // Fall back to an offered detent if the caller asked to open on one
  // that isn't in the set (the assert guarantees the set is non-empty).
  GlassSheetState resolvedInitialState = initialState;
  if (initialState == GlassSheetState.half &&
      !detents.contains(GlassSheetDetent.medium)) {
    resolvedInitialState = GlassSheetState.full;
  } else if (initialState == GlassSheetState.full &&
      !detents.contains(GlassSheetDetent.large)) {
    resolvedInitialState = GlassSheetState.half;
  }

  final effectiveController = controller ?? GlassModalSheetController();
  bool isClosing = false;

  return showGeneralDialog<T>(
    context: context,
    barrierDismissible: isDismissible,
    barrierLabel: 'Dismiss',
    barrierColor: barrierColor,
    useRootNavigator: useRootNavigator,
    transitionDuration: const Duration(milliseconds: 500),
    transitionBuilder: (context, animation, secondaryAnimation, child) {
      return SlideTransition(
        position: Tween<Offset>(begin: const Offset(0, 1), end: Offset.zero)
            .animate(
          CurvedAnimation(parent: animation, curve: Curves.easeOutQuart),
        ),
        child: child,
      );
    },
    pageBuilder: (context, animation, secondaryAnimation) {
      return GlassModalSheetScaffold(
        controller: effectiveController,
        halfSize: halfSize,
        fullSize: fullSize,
        initialState: resolvedInitialState,
        fillThreshold: fillThreshold,
        settings: settings,
        expandedColor: expandedColor,
        mode: mode,
        peekSize: peekSize,
        quality: quality,
        platformViewBackdrop: platformViewBackdrop,
        interactionScale: interactionScale,
        enableInteractionGlow: enableInteractionGlow,
        enableSaturationGlow: enableSaturationGlow,
        peekSettings: peekSettings,
        halfSettings: halfSettings,
        fullSettings: fullSettings,
        stretch: stretch,
        fillTransition: fillTransition,
        showDragIndicator: showDragIndicator,
        dragIndicatorColor: dragIndicatorColor,
        dragIndicatorWidth: dragIndicatorWidth,
        topBorderRadius: topBorderRadius,
        bottomBorderRadius: bottomBorderRadius,
        fullTopBorderRadius: fullTopBorderRadius,
        fullBottomBorderRadius: fullBottomBorderRadius,
        horizontalMargin: horizontalMargin,
        bottomMargin: bottomMargin,
        resistance: resistance,
        snapThreshold: snapThreshold,
        velocityThreshold: velocityThreshold,
        glowColor: glowColor,
        glowRadius: glowRadius,
        suppressInteractionOnChildren: suppressInteractionOnChildren,
        padding: padding,
        enableTopFade: enableTopFade,
        topFadeHeight: topFadeHeight,
        maintainContentGlass: maintainContentGlass,
        fullStateContentSettings: fullStateContentSettings,
        detents: detents,
        dismissible: dismissible,
        enablePeek: enablePeek,
        peekHorizontalMargin: peekHorizontalMargin,
        peekBottomMargin: peekBottomMargin,
        peekWidth: peekWidth,
        peekTopBorderRadius: peekTopBorderRadius,
        peekBottomRadius: peekBottomRadius,
        onStateChanged: (state) {
          onStateChanged?.call(state);
          if (state == GlassSheetState.hidden && !isClosing) {
            isClosing = true;
            Navigator.of(context).pop();
          }
        },
        body: const SizedBox.shrink(),
        sheet: builder(context),
      );
    },
  );
}