showNiceDialog function

Future<bool> showNiceDialog(
  1. BuildContext context, {
  2. required String title,
  3. required String message,
  4. String confirmLabel = 'OK',
  5. String cancelLabel = 'Cancel',
  6. bool destructive = false,
})

Show a NiceToDev-styled confirmation dialog.

Returns true if confirmed, false if cancelled.

Implementation

Future<bool> showNiceDialog(
  BuildContext context, {
  required String title,
  required String message,
  String confirmLabel = 'OK',
  String cancelLabel = 'Cancel',
  bool destructive = false,
}) async {
  final theme = NiceTheme.of(context);
  final result = await showDialog<bool>(
    context: context,
    builder: (ctx) => AlertDialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(theme.borderRadius * 1.5),
      ),
      title: Text(title, style: theme.typography.heading3),
      content: Text(message, style: theme.typography.body),
      actions: [
        TextButton(
          onPressed: () => Navigator.of(ctx).pop(false),
          child: Text(cancelLabel),
        ),
        FilledButton(
          onPressed: () => Navigator.of(ctx).pop(true),
          style: destructive
              ? FilledButton.styleFrom(backgroundColor: theme.colors.error)
              : null,
          child: Text(confirmLabel),
        ),
      ],
    ),
  );
  return result ?? false;
}