import 'package:flutter/material.dart'; import '../services/app_settings.dart'; import '../theme/app_theme.dart'; import 'ui.dart'; /// Dialog with one text field. Returns the trimmed text, or null if cancelled. /// [onReset] adds a secondary red text button ([resetLabel], default "Reset to /// Default") that closes the dialog. Future showTextPrompt( BuildContext context, { required String title, String? message, String initial = '', String? hint, String? note, // small text under the field IconData? fieldIcon, IconData? titleIcon, IconData? confirmIcon, bool obscure = false, bool mono = false, TextInputType keyboardType = TextInputType.text, String? confirmLabel, String? resetLabel, VoidCallback? onReset, }) { final s = AppSettings.instance; final controller = TextEditingController(text: initial); return showDialog( context: context, builder: (dialog) { final c = Palette.current; return AppDialog( title: title, message: message, titleTrailing: titleIcon == null ? null : IconBadge(titleIcon, size: 40), content: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ TextField( controller: controller, autofocus: true, keyboardType: keyboardType, autocorrect: false, obscureText: obscure, style: TextStyle( color: c.ink, fontSize: 15, fontFamily: mono ? AppTheme.mono : null, letterSpacing: mono ? 0.5 : null, ), decoration: InputDecoration( hintText: hint, prefixIcon: fieldIcon == null ? null : Icon(fieldIcon, size: 19, color: c.muted), ), onSubmitted: (v) => Navigator.pop(dialog, v.trim()), ), if (note != null) ...[ const SizedBox(height: 10), Text(note, style: TextStyle(fontSize: 12, height: 1.35, color: c.muted)), ], if (onReset != null) ...[ const SizedBox(height: 6), Align( alignment: Alignment.centerLeft, child: TextButton.icon( style: TextButton.styleFrom(foregroundColor: c.red, padding: const EdgeInsets.symmetric(horizontal: 4)), icon: const Icon(Icons.delete_outline_rounded, size: 18), label: Text(resetLabel ?? s.t('Reset to Default')), onPressed: () { onReset(); Navigator.pop(dialog); }, ), ), ], ], ), actions: [ DialogTextButton(s.t('Cancel'), onTap: () => Navigator.pop(dialog)), PrimaryButton( label: confirmLabel ?? s.t('Save'), icon: confirmIcon, height: 46, onTap: () => Navigator.pop(dialog, controller.text.trim()), ), ], ); }, ); }