generateConfirmDialog static method

String generateConfirmDialog()

Implementation

static String generateConfirmDialog() {
  return '''
import 'package:flutter/material.dart';

class ConfirmDialog extends StatelessWidget {
final String title;
final String message;
final String confirmText;
final String cancelText;
final VoidCallback onConfirm;
final VoidCallback? onCancel;
final bool isDestructive;
final IconData? icon;

const ConfirmDialog({
  Key? key,
  required this.title,
  required this.message,
  this.confirmText = 'Confirm',
  this.cancelText = 'Cancel',
  required this.onConfirm,
  this.onCancel,
  this.isDestructive = false,
  this.icon,
}) : super(key: key);

static Future<bool?> show(
  BuildContext context, {
  required String title,
  required String message,
  String confirmText = 'Confirm',
  String cancelText = 'Cancel',
  bool isDestructive = false,
  IconData? icon,
}) {
  return showDialog<bool>(
    context: context,
    builder: (context) => ConfirmDialog(
      title: title,
      message: message,
      confirmText: confirmText,
      cancelText: cancelText,
      isDestructive: isDestructive,
      icon: icon,
      onConfirm: () => Navigator.of(context).pop(true),
      onCancel: () => Navigator.of(context).pop(false),
    ),
  );
}

@override
Widget build(BuildContext context) {
  final theme = Theme.of(context);
  final actionColor = isDestructive
      ? theme.colorScheme.error
      : theme.colorScheme.primary;

  return AlertDialog(
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(24),
    ),
    title: Column(
      children: [
        if (icon != null) ...[
          Container(
            padding: const EdgeInsets.all(16),
            decoration: BoxDecoration(
              color: actionColor.withOpacity(0.1),
              shape: BoxShape.circle,
            ),
            child: Icon(
              icon,
              size: 32,
              color: actionColor,
            ),
          ),
          const SizedBox(height: 16),
        ],
        Text(
          title,
          style: theme.textTheme.titleLarge?.copyWith(
            fontWeight: FontWeight.bold,
          ),
          textAlign: TextAlign.center,
        ),
      ],
    ),
    content: Text(
      message,
      style: theme.textTheme.bodyLarge?.copyWith(
        color: theme.colorScheme.onSurfaceVariant,
        height: 1.5,
      ),
      textAlign: TextAlign.center,
    ),
    actionsAlignment: MainAxisAlignment.spaceEvenly,
    actionsPadding: const EdgeInsets.fromLTRB(24, 0, 24, 24),
    actions: [
      OutlinedButton(
        onPressed: () {
          onCancel?.call();
          Navigator.of(context).pop(false);
        },
        style: OutlinedButton.styleFrom(
          padding: const EdgeInsets.symmetric(
            horizontal: 32,
            vertical: 16,
          ),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(16),
          ),
        ),
        child: Text(cancelText),
      ),
      FilledButton(
        onPressed: () {
          onConfirm();
          Navigator.of(context).pop(true);
        },
        style: FilledButton.styleFrom(
          backgroundColor: actionColor,
          padding: const EdgeInsets.symmetric(
            horizontal: 32,
            vertical: 16,
          ),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(16),
          ),
        ),
        child: Text(confirmText),
      ),
    ],
  );
}
}
''';
}