showConfirmation static method

Future<bool> showConfirmation(
  1. BuildContext context, {
  2. required String title,
  3. required String content,
  4. String confirmText = 'Confirm',
  5. String cancelText = 'Cancel',
  6. Color? confirmColor,
  7. IconData? titleIcon,
  8. Color? titleIconColor,
})

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;
}