showAlertView function

Future<bool> showAlertView({
  1. required BuildContext context,
  2. String? title,
  3. String? message,
  4. String? confirmTitle,
  5. String? cancelTitle,
  6. VoidCallback? onConfirm,
  7. VoidCallback? onCancel,
  8. bool isDestructiveAction = false,
})

Implementation

Future<bool> showAlertView({
  required BuildContext context,
  String? title,
  String? message,
  String? confirmTitle,
  String? cancelTitle,
  VoidCallback? onConfirm,
  VoidCallback? onCancel,
  bool isDestructiveAction = false,
}) async {
  return await showCupertinoDialog(
    context: context,
    builder: (BuildContext context) {
      return CupertinoAlertDialog(
        title: title != null ? Text(title) : null,
        content: message != null ? Text(message) : null,
        actions: [
          CupertinoDialogAction(
            child: Text(cancelTitle ?? AlertView.defaultCancelTitle),
            onPressed: () {
              Navigator.pop(context, false);
              if (onCancel != null) {
                onCancel();
              }
            },
          ),
          if (confirmTitle != null || onConfirm != null)
            CupertinoDialogAction(
              isDestructiveAction: isDestructiveAction,
              isDefaultAction: true,
              child: Text(confirmTitle ?? AlertView.defaultConfirmTitle),
              onPressed: () {
                Navigator.pop(context, true);
                if (onConfirm != null) {
                  onConfirm();
                }
              },
            ),
        ],
      );
    },
  );
}