showRawDialog<T> function
- required BuildContext context,
- required WidgetBuilder builder,
- RawDialogRouteBuilder<
T> ? routeBuilder, - RouteSettings? routeSettings,
- bool fullscreenDialog = false,
Displays a dialog over the contents of the app.
If windowing is enabled via flutter config --enable-windowing,
then the dialog is displayed in its own window using the windowing system,
rather than as a modal overlay within the current window. This will only
function on platforms that support the dialog window type. True dialog
windows will lack barriers.
The parameter builder builds the content of the dialog.
The context argument is used to look up the Navigator and Theme for
the dialog. It is only used when the method is called. Its corresponding
widget can be safely removed from the tree before the dialog is closed.
The parameter routeBuilder builds the Route that will be pushed to the
Navigator. Defaults to building a RawDialogRoute. When windowing is
available, this parameter will be silently ignored.
The useRootNavigator argument is used to determine whether to push the
dialog to the Navigator furthest from or nearest to the given context.
By default, useRootNavigator is true and the dialog route created by
this method is pushed to the root navigator. It can not be null.
The routeSettings argument is passed to showGeneralDialog,
see RouteSettings for details.
Returns a Future that resolves to the value (if any) that was passed to Navigator.pop when the dialog was closed.
See also:
WindowManager, for more information on how to set up windowing.
Implementation
Future<T?> showRawDialog<T>({
required BuildContext context,
required WidgetBuilder builder,
RawDialogRouteBuilder<T>? routeBuilder,
bool useRootNavigator = true,
RouteSettings? routeSettings,
bool fullscreenDialog = false,
}) {
assert(debugCheckHasWidgetsLocalizations(context));
final NavigatorState navigator = Navigator.of(context, rootNavigator: useRootNavigator);
final WindowRegistry? windowRegistry = WindowRegistry.maybeOf(context);
if (windowRegistry != null && isWindowingEnabled) {
try {
final Size? parentSize = WindowScope.maybeContentSizeOf(context);
return navigator.push<T>(
_DialogWindowRoute<T>(
builder: builder,
parentController: WindowScope.maybeOf(context),
context: context,
settings: routeSettings,
preferredSize: fullscreenDialog ? parentSize : null,
),
);
} on UnsupportedError catch (error, stacktrace) {
// Fallback to normal dialog route if windowing is not supported.
FlutterError.reportError(
FlutterErrorDetails(exception: error, library: 'widgets library', stack: stacktrace),
);
}
}
final Route<T> route =
routeBuilder?.call(context, builder) ??
RawDialogRoute<T>(
pageBuilder:
(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
) => builder(context),
settings: routeSettings,
fullscreenDialog: fullscreenDialog,
);
return navigator.push<T>(route);
}