showModalTopSheet<T> function

Future<T?> showModalTopSheet<T>({
  1. required BuildContext context,
  2. required WidgetBuilder builder,
  3. Color? backgroundColor,
  4. String? barrierLabel,
  5. double? elevation,
  6. ShapeBorder? shape,
  7. Clip? clipBehavior,
  8. BoxConstraints? constraints,
  9. Color? barrierColor,
  10. bool isScrollControlled = false,
  11. double scrollControlDisabledMaxHeightRatio = _defaultScrollControlDisabledMaxHeightRatio,
  12. bool useRootNavigator = false,
  13. bool isDismissible = true,
  14. bool enableDrag = true,
  15. bool? showDragHandle,
  16. bool useSafeArea = true,
  17. RouteSettings? routeSettings,
  18. AnimationController? transitionAnimationController,
  19. Offset? anchorPoint,
})

显示模态 Material Design 顶部工作表。

A DisplayFeature can split the screen into sub-screens. The closest one to anchorPoint is used to render the content.

If no anchorPoint is provided, then Directionality is used:

  • for TextDirection.ltr, anchorPoint is Offset.zero, which will cause the content to appear in the top-left sub-screen.
  • for TextDirection.rtl, anchorPoint is Offset(double.maxFinite, 0), which will cause the content to appear in the top-right sub-screen.

If no anchorPoint is provided, and there is no Directionality ancestor widget in the tree, then the widget asserts during build in debug mode.

'context' 参数用于查找顶部工作表的 NavigatorTheme。它仅在调用该方法时使用。 在顶部工作表关闭之前,可以安全地从树上移除其相应的小部件。

“useRootNavigator”参数确保根导航器在设置为“true”时用于显示 TopSheet。 当一个模态 TopSheet 需要显示在所有其他内容之上,但调用方位于另一个 Navigator 中时,这很有用。

返回一个“Future”,该解析为在关闭模态顶部工作表时传递给 Navigator.pop 的值(如果有)。

“barrierLabel”参数可用于设置自定义 barrierLabel。如果未设置,则默认为 context的 modalBarrierDismissLabel。

另请参阅:

Implementation

Future<T?> showModalTopSheet<T>({
  required BuildContext context,
  required WidgetBuilder builder,
  Color? backgroundColor,
  String? barrierLabel,
  double? elevation,
  ShapeBorder? shape,
  Clip? clipBehavior,
  BoxConstraints? constraints,
  Color? barrierColor,
  bool isScrollControlled = false,
  double scrollControlDisabledMaxHeightRatio =
      _defaultScrollControlDisabledMaxHeightRatio,
  bool useRootNavigator = false,
  bool isDismissible = true,
  bool enableDrag = true,
  bool? showDragHandle,
  bool useSafeArea = true,
  RouteSettings? routeSettings,
  AnimationController? transitionAnimationController,
  Offset? anchorPoint,
}) {
  assert(debugCheckHasMediaQuery(context));
  assert(debugCheckHasMaterialLocalizations(context));

  final NavigatorState navigator =
      Navigator.of(context, rootNavigator: useRootNavigator);
  final MaterialLocalizations localizations = MaterialLocalizations.of(context);
  return navigator.push(
    ModalTopSheetRoute<T>(
      builder: builder,
      capturedThemes:
          InheritedTheme.capture(from: context, to: navigator.context),
      isScrollControlled: isScrollControlled,
      scrollControlDisabledMaxHeightRatio: scrollControlDisabledMaxHeightRatio,
      barrierLabel: barrierLabel ?? localizations.scrimLabel,
      barrierOnTapHint:
          localizations.scrimOnTapHint(localizations.bottomSheetLabel),
      backgroundColor: backgroundColor,
      elevation: elevation,
      shape: shape,
      clipBehavior: clipBehavior,
      constraints: constraints,
      isDismissible: isDismissible,
      modalBarrierColor: barrierColor ??
          TopSheetTheme.of(context).data?.modalBarrierColor ??
          Theme.of(context).bottomSheetTheme.modalBarrierColor,
      enableDrag: enableDrag,
      showDragHandle: showDragHandle,
      settings: routeSettings,
      transitionAnimationController: transitionAnimationController,
      anchorPoint: anchorPoint,
      useSafeArea: useSafeArea,
    ),
  );
}