import 'package:flutter/material.dart'; import '../../../ui/text/monospace.dart'; import 'chat_shell_command.dart'; /// The chat actions menu's "Run command…": a small host dialog with one /// command field. Returns the trimmed command, or null when cancelled. Future showChatShellRunDialog(BuildContext context) => showDialog( context: context, builder: (_) => const ChatShellRunDialog(), ); class ChatShellRunDialog extends StatefulWidget { const ChatShellRunDialog({super.key}); @override State createState() => _ChatShellRunDialogState(); } class _ChatShellRunDialogState extends State { final TextEditingController _text = TextEditingController(); @override void dispose() { _text.dispose(); super.dispose(); } void _submit() { final command = _text.text.trim(); Navigator.pop(context, command.isEmpty ? null : command); } void _cancel() => Navigator.pop(context); @override Widget build(BuildContext context) { const mono = TextStyle(fontFamily: appMonospaceFamily); return AlertDialog( title: const Text(chatShellRunDialogTitle), content: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const Text(chatShellModeHint), const SizedBox(height: 12), TextField( key: const Key('chat-shell-run-field'), controller: _text, autofocus: true, style: mono, decoration: const InputDecoration( labelText: 'Command', prefixText: '\$ ', ), onSubmitted: (_) => _submit(), ), ], ), actions: [ TextButton(onPressed: _cancel, child: const Text('Cancel')), FilledButton( key: const Key('chat-shell-run-confirm'), onPressed: _submit, child: const Text(chatShellRunDialogConfirm), ), ], ); } }