showConfirmationDialog static method
Future<bool?>
showConfirmationDialog(
- BuildContext context, {
- String title = '',
- String message = '',
- String textConfirm = 'OK',
- String textCancel = 'Cancel',
Implementation
static Future<bool?> showConfirmationDialog(
BuildContext context, {
String title = '',
String message = '',
String textConfirm = 'OK', // Default text for confirm button
String textCancel = 'Cancel', // Default text for cancel button
}) async {
if (title.isEmpty) title = AppProperties.getAppName(); // Use default app name if title is empty
return showDialog<bool?>( // Specify the return type of showDialog
context: context,
barrierDismissible: false, // User must tap button!
builder: (BuildContext context) {
return AlertDialog(
backgroundColor: AppColor.getMain(), // Consistent with showAlert
title: Text(title),
content: Text(message),
actions: <Widget>[
// Cancel Button
TextButton(
child: Text(
textCancel,
style: const TextStyle(color: AppColor.white), // White text color
),
onPressed: () {
Navigator.of(context).pop(false); // Return false when cancelled
},
),
// Confirm Button
TextButton(
child: Text(
textConfirm,
style: const TextStyle(color: AppColor.white), // White text color
),
onPressed: () {
Navigator.of(context).pop(true); // Return true when confirmed
},
),
],
);
},
);
}