96de9f5bea
Keep the Material-only conversation implementation while preserving public Cupertino parameters for callers. Narrow affected tests to Material hosts so the dead platform paths are no longer exercised.
64 lines
1.9 KiB
Dart
64 lines
1.9 KiB
Dart
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<ChatCommand> commands;
|
|
|
|
/// The highlighted row. Callers clamp it to this list.
|
|
final int selectedIndex;
|
|
|
|
final ValueChanged<ChatCommand> 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<String>('chat-command-${commands[index].name}'),
|
|
selected: index == selectedIndex,
|
|
title: Text('/${commands[index].name}'),
|
|
subtitle: Text(commands[index].summary),
|
|
onTap: () => onSelected(commands[index]),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|