showModalTopSheet<T> function
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 isDismissible = true,
- bool enableDrag = true,
- bool? showDragHandle,
- bool useSafeArea = true,
- RouteSettings? routeSettings,
- AnimationController? transitionAnimationController,
- 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
isOffset.zero
, which will cause the content to appear in the top-left sub-screen. - for TextDirection.rtl,
anchorPoint
isOffset(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' 参数用于查找顶部工作表的 Navigator 和 Theme。它仅在调用该方法时使用。 在顶部工作表关闭之前,可以安全地从树上移除其相应的小部件。
“useRootNavigator”参数确保根导航器在设置为“true”时用于显示 TopSheet。 当一个模态 TopSheet 需要显示在所有其他内容之上,但调用方位于另一个 Navigator 中时,这很有用。
返回一个“Future”,该解析为在关闭模态顶部工作表时传递给 Navigator.pop 的值(如果有)。
“barrierLabel”参数可用于设置自定义 barrierLabel。如果未设置,则默认为 context的 modalBarrierDismissLabel。
另请参阅:
- TopSheet, 它成为作为“builder”参数传递给 showModalTopSheet 的函数返回的小部件的父级。
- DraggableScrollableSheet, 创建一个底部工作表,该工作表会增长,然后在达到最大尺寸后变得可滚动。
- DisplayFeatureSubScreen, 它记录了 DisplayFeature 如何将屏幕拆分为子屏幕的细节。
- Material 2 规范位于 m2.material.io/components/sheets-bottom.
- Material 3 规范位于 m3.material.io/components/bottom-sheets/overview.
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,
),
);
}