showConfirmationDialog method

void showConfirmationDialog({
  1. required BuildContext context,
  2. required String message,
  3. String title = 'Confirmation',
  4. String confirmText = 'Yes',
  5. String cancelText = 'No',
  6. VoidCallback? onConfirm,
  7. VoidCallback? onCancel,
})

Shows a confirmation dialog with Yes and No buttons

Implementation

void showConfirmationDialog({
  required BuildContext context,
  required String message,
  String title = 'Confirmation',
  String confirmText = 'Yes',
  String cancelText = 'No',
  VoidCallback? onConfirm,
  VoidCallback? onCancel,
}) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text(title),
        content: Text(message),
        actions: [
          TextButton(
            onPressed: () {
              Navigator.of(context).pop(); // Close the dialog
              if (onCancel != null) {
                onCancel();
              }
            },
            child: Text(cancelText),
          ),
          TextButton(
            onPressed: () {
              Navigator.of(context).pop(); // Close the dialog
              if (onConfirm != null) {
                onConfirm();
              }
            },
            child: Text(confirmText),
          ),
        ],
      );
    },
  );
}