showModal<T> function

Future<T?> showModal<T>(
  1. {required BuildContext context,
  2. ModalConfiguration configuration = const FadeScaleTransitionConfiguration(),
  3. bool useRootNavigator = true,
  4. required WidgetBuilder builder,
  5. RouteSettings? routeSettings,
  6. ImageFilter? filter}

Displays a modal above the current contents of the app.

Content below the modal is dimmed with a ModalBarrier.

The context argument is used to look up the Navigator for the modal. It is only used when the method is called. Its corresponding widget can be safely removed from the tree before the modal is closed.

The configuration argument is used to determine characteristics of the modal route that will be displayed, such as the enter and exit transitions, the duration of the transitions, and modal barrier properties. By default, configuration is FadeScaleTransitionConfiguration.

The useRootNavigator argument is used to determine whether to push the modal to the Navigator furthest from or nearest to the given context. By default, useRootNavigator is true and the modal route created by this method is pushed to the root navigator. If the application has multiple Navigator objects, it may be necessary to call Navigator.of(context, rootNavigator: true).pop(result) to close the modal rather than just Navigator.pop(context, result).

Returns a Future that resolves to the value (if any) that was passed to Navigator.pop when the modal was closed.

See also:

  • ModalConfiguration, which is the configuration object used to define the modal's characteristics.


Future<T?> showModal<T>({
  required BuildContext context,
  ModalConfiguration configuration = const FadeScaleTransitionConfiguration(),
  bool useRootNavigator = true,
  required WidgetBuilder builder,
  RouteSettings? routeSettings,
  ui.ImageFilter? filter,
}) {
  String? barrierLabel = configuration.barrierLabel;
  // Avoid looking up [MaterialLocalizations.of(context).modalBarrierDismissLabel]
  // if there is no dismissible barrier.
  if (configuration.barrierDismissible && configuration.barrierLabel == null) {
    barrierLabel = MaterialLocalizations.of(context).modalBarrierDismissLabel;
  assert(!configuration.barrierDismissible || barrierLabel != null);
  return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(
      barrierColor: configuration.barrierColor,
      barrierDismissible: configuration.barrierDismissible,
      barrierLabel: barrierLabel,
      transitionBuilder: configuration.transitionBuilder,
      transitionDuration: configuration.transitionDuration,
      reverseTransitionDuration: configuration.reverseTransitionDuration,
      builder: builder,
      routeSettings: routeSettings,
      filter: filter,