/// * [DisplayFeatureSubScreen], which documents the specifics of how
/// [DisplayFeature]s can split the screen into sub-screens.
/// * [showDialog], which displays a Material-style dialog.
/// * [showCupertinoDialog], which displays an iOS-style dialog.
Future<T?> showGeneralDialog<T extends Object?>({
required BuildContext context,
required RoutePageBuilder pageBuilder,
bool barrierDismissible = false,
String? barrierLabel,
Color barrierColor = const Color(0x80000000),
Duration transitionDuration = const Duration(milliseconds: 200),
RouteTransitionsBuilder? transitionBuilder,
bool useRootNavigator = true,
RouteSettings? routeSettings,
Offset? anchorPoint,
}) {
assert(!barrierDismissible || barrierLabel != null);
return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(RawDialogRoute<T>(
pageBuilder: pageBuilder,
barrierDismissible: barrierDismissible,
barrierLabel: barrierLabel,
barrierColor: barrierColor,
transitionDuration: transitionDuration,
transitionBuilder: transitionBuilder,
settings: routeSettings,
anchorPoint: anchorPoint,
));
}
实现很简单,直接调用Navigator
的push
方法打开了一个新的对话框路由RawDialogRoute
,然后返回了push
的返回值。可见对话框实际上正是通过路由的形式实现的,这也是为什么我们可以使用Navigator
的pop
方法来退出对话框的原因。关于对话框的样式定制在RawDialogRoute
中,没有什么新的东西,读者可以自行查看。这里我只取一部分
class RawDialogRoute<T> extends PopupRoute<T> {
/// A general dialog route which allows for customization of the dialog popup.
RawDialogRoute({
required RoutePageBuilder pageBuilder,
bool barrierDismissible = true,
Color? barrierColor = const Color(0x80000000),
String? barrierLabel,
Duration transitionDuration = const Duration(milliseconds: 200),
RouteTransitionsBuilder? transitionBuilder,
super.settings,
this.anchorPoint,
super.traversalEdgeBehavior,
}) : _pageBuilder = pageBuilder,
_barrierDismissible = barrierDismissible,
_barrierLabel = barrierLabel,
_barrierColor = barrierColor,
_transitionDuration = transitionDuration,
_transitionBuilder = transitionBuilder;
---....此处省略----
}