import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'walkthrough_steps.dart'; /// The harness page's command: an agent picker and the one command it selects, /// with a single copy button for that command. class WalkthroughHarnessCommand extends StatefulWidget { const WalkthroughHarnessCommand({super.key}); @override State createState() => _WalkthroughHarnessCommandState(); } class _WalkthroughHarnessCommandState extends State { String _agent = harnessAgents.first; bool _copied = false; Future _copy(String command) async { try { await Clipboard.setData(ClipboardData(text: command)); } catch (_) { // The command stays selectable, so a failed copy never claims success. return; } if (!mounted) return; setState(() => _copied = true); } @override Widget build(BuildContext context) { final scheme = Theme.of(context).colorScheme; final command = harnessSetupCommand(_agent); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text('Agent', style: Theme.of(context).textTheme.labelLarge), const SizedBox(height: 8), Wrap( spacing: 8, runSpacing: 8, children: [ for (final agent in harnessAgents) ChoiceChip( key: ValueKey('walkthrough.agent.$agent'), label: Text(agent), selected: agent == _agent, onSelected: (_) => setState(() { _agent = agent; _copied = false; }), ), ], ), const SizedBox(height: 12), DecoratedBox( decoration: BoxDecoration( color: scheme.surfaceContainerHighest, borderRadius: BorderRadius.circular(12), ), child: Padding( padding: const EdgeInsets.only(left: 12, right: 4), child: Row( children: [ Expanded( child: SelectableText( command, key: const ValueKey('walkthrough.command'), style: Theme.of(context).textTheme.bodyLarge, ), ), IconButton( key: const ValueKey('walkthrough.copy'), tooltip: _copied ? 'Command copied' : 'Copy command', onPressed: () => _copy(command), icon: Icon(_copied ? Icons.check : Icons.copy_outlined), ), ], ), ), ), ], ); } }