showConfirmationDialog function

dynamic showConfirmationDialog(
  1. BuildContext context, {
  2. Widget? transitionAnimation,
  3. String negativeBtnText = kNo,
  4. String positiveBtnText = kYes,
  5. bool barrierDismissible = false,
  6. Color dividerColor = Colors.blue,
  7. Color negativeBtnColor = Colors.red,
  8. Color positiveBtnColor = Colors.blue,
  9. TextAlign descTextAlign = TextAlign.center,
  10. TextAlign titleTextAlign = TextAlign.center,
  11. Duration transitionDuration = const Duration(milliseconds: 400),
  12. DialogAnimationType dialogAnimationType = DialogAnimationType.grow,
  13. TextStyle descStyle = const TextStyle(fontSize: 16, letterSpacing: 0.27, color: Colors.black),
  14. TextStyle titleStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.bold),
  15. TextStyle positiveBtnStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.w400),
  16. TextStyle negativeBtnStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.w400),
  17. required String title,
  18. required String description,
  19. required VoidCallback onPositivePressed,
})

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

Implementation

showConfirmationDialog(
  BuildContext context, {
  Widget? transitionAnimation,
  String negativeBtnText = kNo,
  String positiveBtnText = kYes,
  bool barrierDismissible = false,
  Color dividerColor = Colors.blue,
  Color negativeBtnColor = Colors.red,
  Color positiveBtnColor = 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 titleStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.bold),
  TextStyle positiveBtnStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.w400),
  TextStyle negativeBtnStyle = const TextStyle(fontSize: 18, letterSpacing: 0.27, fontWeight: FontWeight.w400),
  required String title,
  required String description,
  required VoidCallback onPositivePressed,
}) {
  return showGeneralDialog(
    context: context,
    barrierLabel: '',
    barrierDismissible: barrierDismissible,
    transitionDuration: transitionDuration,
    barrierColor: Colors.black.withOpacity(0.5),
    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 _CustomConfirmDialog(
        title: title,
        descStyle: descStyle,
        titleStyle: titleStyle,
        description: description,
        dividerColor: dividerColor,
        descTextAlign: descTextAlign,
        titleTextAlign: titleTextAlign,
        positiveBtnText: positiveBtnText,
        negativeBtnText: negativeBtnText,
        positiveBtnColor: positiveBtnColor,
        negativeBtnColor: negativeBtnColor,
        positiveBtnStyle: positiveBtnStyle,
        negativeBtnStyle: negativeBtnStyle,
        onPositivePressed: onPositivePressed,
      );
    },
  );
}