showCustomDialog function Null safety

dynamic showCustomDialog(
  1. BuildContext context,
  2. {String btnText = kOK,
  3. Color btnColor = Colors.blue,
  4. bool barrierDismissible = false,
  5. Color dividerColor = Colors.blue,
  6. TextAlign descTextAlign = TextAlign.center,
  7. TextAlign titleTextAlign = TextAlign.center,
  8. Duration transitionDuration = const Duration(milliseconds: 400),
  9. DialogAnimationType dialogAnimationType = DialogAnimationType.grow,
  10. TextStyle descStyle = const TextStyle(fontSize: 16, letterSpacing: 0.27, color: Colors.black),
  11. TextStyle btnStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.w400),
  12. TextStyle titleStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.bold),
  13. required String title,
  14. required String description}
)

This method will show a dialog box with custom UI and animation

Implementation

showCustomDialog(
  BuildContext context, {
  String btnText = kOK,
  Color btnColor = Colors.blue,
  bool barrierDismissible = false,
  Color dividerColor = Colors.blue,
  TextAlign descTextAlign = TextAlign.center,
  TextAlign titleTextAlign = TextAlign.center,
  Duration transitionDuration = const Duration(milliseconds: 400),
  DialogAnimationType dialogAnimationType = DialogAnimationType.grow,
  TextStyle descStyle = const TextStyle(fontSize: 16, letterSpacing: 0.27, color: Colors.black),
  TextStyle btnStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.w400),
  TextStyle titleStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.bold),
  required String title,
  required String description,
}) {
  return showGeneralDialog(
    context: context,
    barrierLabel: '',
    barrierDismissible: barrierDismissible,
    transitionDuration: transitionDuration,
    barrierColor: Colors.black.withOpacity(0.4),
    transitionBuilder: (context, animation, secondaryAnimation, child) {
      switch (dialogAnimationType) {
        case DialogAnimationType.grow:
          return Animations.grow(animation, child);

        case DialogAnimationType.fromTop:
          return Animations.fromTop(animation, child);

        case DialogAnimationType.fromLeft:
          return Animations.fromLeft(animation, child);

        case DialogAnimationType.fromRight:
          return Animations.fromRight(animation, child);

        case DialogAnimationType.fromBottom:
          return Animations.fromBottom(animation, child);

        default:
          return Animations.grow(animation, child);
      }
    },
    pageBuilder: (BuildContext context, animation, secondaryAnimation) {
      return _CustomDialog(
        title: title,
        btnText: btnText,
        btnColor: btnColor,
        btnStyle: btnStyle,
        descStyle: descStyle,
        titleStyle: titleStyle,
        description: description,
        dividerColor: dividerColor,
        descTextAlign: descTextAlign,
        titleTextAlign: titleTextAlign,
      );
    },
  );
}