showConfirmationDialog method
void
showConfirmationDialog({
- required BuildContext context,
- required String message,
- String title = 'Confirmation',
- String confirmText = 'Yes',
- String cancelText = 'No',
- VoidCallback? onConfirm,
- 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),
),
],
);
},
);
}