confirm static method
Shows a confirmation dialog and returns true only when confirmed.
Implementation
static Future<bool> confirm(
BuildContext context, {
required String title,
required String message,
String confirmLabel = 'Confirm',
String cancelLabel = 'Cancel',
Widget? icon,
bool isDestructive = false,
bool barrierDismissible = true,
}) async {
final result = await show<bool>(
context,
barrierDismissible: barrierDismissible,
builder: (dialogContext) => AlertDialog(
icon: icon,
title: Text(title),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: Text(cancelLabel),
),
FilledButton(
style: isDestructive
? FilledButton.styleFrom(
backgroundColor: Theme.of(dialogContext).colorScheme.error,
foregroundColor: Theme.of(
dialogContext,
).colorScheme.onError,
)
: null,
onPressed: () => Navigator.of(dialogContext).pop(true),
child: Text(confirmLabel),
),
],
),
);
return result ?? false;
}