showConfirmationDialog function
- BuildContext context, {
- required String title,
- required String message,
- String? confirmLabel,
- String? cancelLabel,
Shows a confirmation dialog with the given title
and message
to the user.
The dialog will have a confirm and a cancel button and will return true
if the confirm button is pressed and false
if the cancel button is pressed.
Implementation
Future<bool> showConfirmationDialog(
BuildContext context, {
required String title,
required String message,
String? confirmLabel,
String? cancelLabel,
}) async {
final result = await showGenericDialog<bool>(
context,
title: title,
content: Text(message),
actions: [
PrimaryDialogAction(
label: confirmLabel ?? 'Confirm',
onPressed: (context) {
Navigator.of(context).pop(true);
},
),
SecondaryDialogAction(
label: cancelLabel ?? 'Cancel',
onPressed: (context) {
Navigator.of(context).pop(false);
},
),
],
);
return result ?? false;
}