dialog<T> method

Future<T?> dialog<T>(
  1. Widget widget, {
  2. bool barrierDismissible = true,
  3. Color? barrierColor,
  4. bool useSafeArea = true,
  5. GlobalKey<NavigatorState>? navigatorKey,
  6. Object? arguments,
  7. Duration? transitionDuration,
  8. Curve? transitionCurve,
  9. String? name,
  10. RouteSettings? routeSettings,
})

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,
  GlobalKey<NavigatorState>? navigatorKey,
  Object? arguments,
  Duration? transitionDuration,
  Curve? transitionCurve,
  String? name,
  RouteSettings? routeSettings,
}) {
  assert(debugCheckHasMaterialLocalizations(context!));

  //  final theme = Theme.of(context, shadowThemeOnly: true);
  final theme = Theme.of(context!);
  if (arguments != null) {
    routing.args = arguments;
  }
  return generalDialog<T>(
    pageBuilder: (buildContext, animation, secondaryAnimation) {
      final pageChild = widget;
      Widget dialog = Builder(builder: (context) {
        return Theme(data: theme, child: 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,
      );
    },
    navigatorKey: navigatorKey,
    routeSettings:
        routeSettings ?? RouteSettings(arguments: arguments, name: name),
  );
}