showDialogWithAnimation<T> function

Future<T?> showDialogWithAnimation<T>({
  1. required BuildContext context,
  2. bool barrierDismissible = true,
  3. Color? barrierColor = Colors.black54,
  4. required Widget child,
})

Displays a dialog with fade-in animation.

context is the build context. barrierDismissible allows tapping outside to dismiss. barrierColor sets the background dim color. child is the dialog widget to display.

Implementation

Future<T?> showDialogWithAnimation<T>({
  required BuildContext context,
  bool barrierDismissible = true,
  Color? barrierColor = Colors.black54,
  required Widget child,
}) {
  return showGeneralDialog(
    context: context,
    pageBuilder: (buildContext, animation, secondaryAnimation) {
      return Builder(
        builder: (context) {
          return child;
        },
      );
    },
    barrierDismissible: barrierDismissible,
    barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
    barrierColor: barrierColor ?? Colors.black54,
    transitionDuration: const Duration(milliseconds: 100),
    transitionBuilder: (context, animation, secondaryAnimation, child) {
      return Opacity(
        opacity: animation.value,
        child: child,
      );
    },
  );
}