import 'package:flutter/material.dart'; import '../domain/chat_commands.dart'; /// The command palette above the composer: the recorded commands matching the /// slash word, each with its own `/name` and summary. /// /// Rows are standard Material `ListTile`s, so typography, colours and text /// scaling stay the theme's. The list is content-sized and never imposes a fixed height; /// a viewport-bound scroll keeps a tall text scale reachable. class ChatCommandPalette extends StatelessWidget { const ChatCommandPalette({ super.key, required this.commands, required this.selectedIndex, required this.onSelected, }); final List commands; /// The highlighted row. Callers clamp it to this list. final int selectedIndex; final ValueChanged onSelected; @override Widget build(BuildContext context) { if (commands.isEmpty) return const SizedBox.shrink(); return ConstrainedBox( constraints: BoxConstraints( maxHeight: MediaQuery.sizeOf(context).height * 0.4, ), child: SingleChildScrollView( child: Semantics( container: true, label: 'Command suggestions', child: _materialRows(context), ), ), ); } Widget _materialRows(BuildContext context) { return Card( key: const Key('chat-command-palette'), margin: EdgeInsets.zero, clipBehavior: Clip.antiAlias, child: Column( mainAxisSize: MainAxisSize.min, children: [ for (var index = 0; index < commands.length; index += 1) ListTile( key: ValueKey('chat-command-${commands[index].name}'), selected: index == selectedIndex, title: Text('/${commands[index].name}'), subtitle: Text(commands[index].summary), onTap: () => onSelected(commands[index]), ), ], ), ); } }