showConfirmation static method
Shows a confirmation dialog with customizable title, content, and buttons.
Returns true if user confirmed, false if cancelled or dismissed.
Implementation
static Future<bool> showConfirmation(
BuildContext context, {
required String title,
required String content,
String confirmText = 'Confirm',
String cancelText = 'Cancel',
Color? confirmColor,
IconData? titleIcon,
Color? titleIconColor,
}) async {
final result = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: titleIcon != null
? Row(
children: [
Icon(titleIcon, color: titleIconColor),
const SizedBox(width: 8),
Text(title),
],
)
: Text(title),
content: Text(content),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: Text(cancelText),
),
ElevatedButton(
onPressed: () => Navigator.pop(ctx, true),
style: confirmColor != null
? ElevatedButton.styleFrom(
backgroundColor: confirmColor,
foregroundColor: Colors.white,
)
: null,
child: Text(confirmText),
),
],
),
);
return result == true;
}