dialog<T> method

Future<T> dialog<T>(
  1. Widget widget,
  2. {bool barrierDismissible = true,
  3. Color barrierColor,
  4. bool useSafeArea = true,
  5. bool useRootNavigator = true,
  6. RouteSettings routeSettings,
  7. Duration transitionDuration,
  8. Curve transitionCurve}
)

Show a dialog. You can pass a transitionDuration and/or transitionCurve, overriding the defaults when the dialog shows up and closes. When the dialog closes, uses those animations in reverse.

Implementation

Future<T> dialog<T>(
  Widget widget, {
  bool barrierDismissible = true,
  Color barrierColor,
  bool useSafeArea = true,
  bool useRootNavigator = true,
  RouteSettings routeSettings,
  Duration transitionDuration,
  Curve transitionCurve,
}) {
  assert(widget != null);
  assert(barrierDismissible != null);
  assert(useSafeArea != null);
  assert(useRootNavigator != null);
  assert(debugCheckHasMaterialLocalizations(context));

  final theme = Theme.of(context, shadowThemeOnly: true);
  return generalDialog(
    pageBuilder: (buildContext, animation, secondaryAnimation) {
      final pageChild = widget;
      Widget dialog = Builder(builder: (context) {
        return theme != null
            ? Theme(data: theme, child: pageChild)
            : pageChild;
      });
      if (useSafeArea) {
        dialog = SafeArea(child: dialog);
      }
      return dialog;
    },
    barrierDismissible: barrierDismissible,
    barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
    barrierColor: barrierColor ?? Colors.black54,
    transitionDuration: transitionDuration ?? defaultDialogTransitionDuration,
    transitionBuilder: (context, animation, secondaryAnimation, child) {
      return FadeTransition(
        opacity: CurvedAnimation(
          parent: animation,
          curve: transitionCurve ?? defaultDialogTransitionCurve,
        ),
        child: child,
      );
    },
    useRootNavigator: useRootNavigator,
    routeSettings: routeSettings,
  );
}