showDialog<T> function
Future<T?>
showDialog<T>({
- required BuildContext context,
- required RouteWidgetBuilder builder,
- bool barrierDismissible = true,
- Color? barrierColor,
- String? barrierLabel,
- bool useSafeArea = true,
- Alignment alignment = Alignment.center,
- num? width,
- num? height,
- RouteSettings? routeSettings,
- AnimationStyle? animationStyle,
Shows a material design dialog.
The dialog route is created and pushed onto the navigator that most
closely encloses the given context.
Returns a Future that resolves to the value passed to
Navigator.pop when the dialog is dismissed.
final confirmed = await showDialog<bool>(
context: context,
builder: (ctx) => DialogConfirm(
title: 'Delete?',
message: 'This cannot be undone.',
),
);
Implementation
Future<T?> showDialog<T>({
required BuildContext context,
required RouteWidgetBuilder builder,
bool barrierDismissible = true,
Color? barrierColor,
String? barrierLabel,
bool useSafeArea = true,
Alignment alignment = Alignment.center,
num? width,
num? height,
RouteSettings? routeSettings,
AnimationStyle? animationStyle,
}) {
// Capture the caller's theme so the dialog inherits the correct theme
// even though it renders in the navigator's overlay (which may have a
// different ThemeScope ancestor).
final capturedTheme = ThemeScope.maybeOf(context);
final route = DialogRoute<T>(
builder: builder,
barrierDismissible: barrierDismissible,
barrierColor: barrierColor,
barrierLabel: barrierLabel,
useSafeArea: useSafeArea,
alignment: alignment,
width: width,
height: height,
animationStyle: animationStyle,
capturedTheme: capturedTheme,
settings: routeSettings ?? RouteSettings(name: DialogRoute.routeName),
);
return Navigator.of(context).push<T>(route);
}