show static method

Future show({
  1. required BuildContext context,
  2. String? title,
  3. String? text,
  4. Widget? widget,
  5. required EasyAlertType type,
  6. EasyAlertAnimType animType = EasyAlertAnimType.scale,
  7. bool barrierDismissible = true,
  8. VoidCallback? onConfirmBtnTap,
  9. VoidCallback? onCancelBtnTap,
  10. String confirmBtnText = 'Okay',
  11. String cancelBtnText = 'Cancel',
  12. Color confirmBtnColor = Colors.blue,
  13. TextStyle? confirmBtnTextStyle,
  14. TextStyle? cancelBtnTextStyle,
  15. Color backgroundColor = Colors.white,
  16. Color titleColor = Colors.black,
  17. Color textColor = Colors.black,
  18. Color? barrierColor,
  19. bool showCancelBtn = false,
  20. double borderRadius = 15.0,
  21. String? customAsset,
  22. double? width,
  23. Duration? autoCloseDuration,
})

Instantly display animated alert dialogs such as success, error, warning, confirm, loading or even a custom dialog.

Implementation

static Future show({
  /// BuildContext
  required BuildContext context,

  /// Title of the dialog
  String? title,

  /// Text of the dialog
  String? text,

  /// Custom Widget of the dialog
  Widget? widget,

  /// Alert type [success, error, warning, confirm, info, loading, custom]
  required EasyAlertType type,

  /// Animation type  [scale, rotate, slideInDown, slideInUp, slideInLeft, slideInRight]
  EasyAlertAnimType animType = EasyAlertAnimType.scale,

  /// Barrier Dissmisable
  bool barrierDismissible = true,

  /// Triggered when confirm button is tapped
  VoidCallback? onConfirmBtnTap,

  /// Triggered when cancel button is tapped
  VoidCallback? onCancelBtnTap,

  /// Confirmation button text
  String confirmBtnText = 'Okay',

  /// Cancel button text
  String cancelBtnText = 'Cancel',

  /// Color for confirm button
  Color confirmBtnColor = Colors.blue,

  /// TextStyle for confirm button
  TextStyle? confirmBtnTextStyle,

  /// TextStyle for cancel button
  TextStyle? cancelBtnTextStyle,

  /// Backgroung Color for dialog
  Color backgroundColor = Colors.white,

  /// Color of title
  Color titleColor = Colors.black,

  /// Color of text
  Color textColor = Colors.black,

  /// Barrier Color of dialog
  Color? barrierColor,

  /// Determines if cancel button is shown or not
  bool showCancelBtn = false,

  /// Dialog Border Radius
  double borderRadius = 15.0,

  /// Asset path of your Image file
  String? customAsset,

  /// Width of the dialog
  double? width,

  /// Determines how long the dialog stays open for before closing, [default] is null. When it is null, it won't autoclose
  Duration? autoCloseDuration,
}) {
  if (autoCloseDuration != null) {
    Future.delayed(autoCloseDuration, () {
      Navigator.of(context, rootNavigator: true).pop();
    });
  }

  final options = EasyAlertOptions(
    title: title,
    text: text,
    widget: widget,
    type: type,
    animType: animType,
    barrierDismissible: barrierDismissible,
    onConfirmBtnTap: onConfirmBtnTap,
    onCancelBtnTap: onCancelBtnTap,
    confirmBtnText: confirmBtnText,
    cancelBtnText: cancelBtnText,
    confirmBtnColor: confirmBtnColor,
    confirmBtnTextStyle: confirmBtnTextStyle,
    cancelBtnTextStyle: cancelBtnTextStyle,
    backgroundColor: backgroundColor,
    titleColor: titleColor,
    textColor: textColor,
    showCancelBtn: showCancelBtn,
    borderRadius: borderRadius,
    customAsset: customAsset,
    width: width,
  );

  final child = AlertDialog(
    contentPadding: EdgeInsets.zero,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(borderRadius),
    ),
    content: EasyAlertContainer(
      options: options,
    ),
  );

  return showGeneralDialog(
    barrierColor: barrierColor ?? Colors.black.withOpacity(0.5),
    transitionBuilder: (context, anim1, __, widget) {
      switch (animType) {
        case EasyAlertAnimType.scale:
          return Animate.scale(child: child, animation: anim1);

        case EasyAlertAnimType.rotate:
          return Animate.rotate(child: child, animation: anim1);

        case EasyAlertAnimType.slideInDown:
          return Animate.slideInDown(child: child, animation: anim1);

        case EasyAlertAnimType.slideInUp:
          return Animate.slideInUp(child: child, animation: anim1);

        case EasyAlertAnimType.slideInLeft:
          return Animate.slideInLeft(child: child, animation: anim1);

        case EasyAlertAnimType.slideInRight:
          return Animate.slideInRight(child: child, animation: anim1);

        default:
          return child;
      }
    },
    transitionDuration: const Duration(milliseconds: 200),
    barrierDismissible:
        autoCloseDuration != null ? false : barrierDismissible,
    barrierLabel: '',
    context: context,
    pageBuilder: (context, _, __) => Container(),
  );
}