Polish adaptive app chrome

This commit is contained in:
2026-10-31 06:02:02 +00:00
parent 06f6eda360
commit 480f8843eb
14 changed files with 228 additions and 53 deletions
@@ -60,6 +60,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
final picker = _ChatModePicker(
load: () => repository.modes(widget.sessionId),
current: _mode,
currentName: _name,
cupertino: cupertino,
choose: (mode) async {
final applied = await repository.selectMode(widget.sessionId, mode.id);
@@ -95,6 +96,9 @@ class _ChatModeControlState extends State<ChatModeControl> {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final label = _name;
// At phone widths the title and a named mode cannot both remain useful.
// Keep the mode's shield, whose semantic label and picker still name it.
final iconOnly = cupertino && MediaQuery.sizeOf(context).width < 600;
final content = Row(
mainAxisSize: MainAxisSize.min,
children: [
@@ -103,8 +107,10 @@ class _ChatModeControlState extends State<ChatModeControl> {
? CupertinoIcons.shield_lefthalf_fill
: Icons.shield_outlined,
),
const SizedBox(width: 4),
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
if (!iconOnly) ...[
const SizedBox(width: 4),
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
],
],
);
const key = Key('chat-mode');
@@ -146,12 +152,14 @@ class _ChatModePicker extends StatefulWidget {
const _ChatModePicker({
required this.load,
required this.current,
required this.currentName,
required this.cupertino,
required this.choose,
});
final Future<({List<JsonMap> modes, String current})> Function() load;
final String current;
final String currentName;
final bool cupertino;
final Future<void> Function(_Mode mode) choose;
@@ -165,6 +173,23 @@ class _ChatModePickerState extends State<_ChatModePicker> {
bool _busy = false;
String? _error;
/// The session row has already named the selected mode. Some harnesses do
/// not return a catalog, so retain that known value in the picker rather
/// than opening an action sheet with no visible mode.
List<_Mode> get _visibleModes {
final modes = _modes;
if (modes == null ||
_current.isEmpty ||
widget.currentName.isEmpty ||
modes.any((mode) => mode.id == _current)) {
return modes ?? const [];
}
return [
...modes,
(id: _current, name: widget.currentName, description: ''),
];
}
@override
void initState() {
super.initState();
@@ -230,7 +255,8 @@ class _ChatModePickerState extends State<_ChatModePicker> {
Widget _materialSheet(BuildContext context) {
final theme = Theme.of(context);
final modes = _modes;
final modes = _visibleModes;
final loaded = _modes != null;
return SafeArea(
child: ListView(
key: const Key('chat-mode-sheet'),
@@ -248,7 +274,7 @@ class _ChatModePickerState extends State<_ChatModePicker> {
style: TextStyle(color: theme.colorScheme.error),
),
),
if (modes == null)
if (!loaded)
const Padding(
padding: EdgeInsets.all(16),
child: Center(child: CircularProgressIndicator()),
@@ -274,7 +300,8 @@ class _ChatModePickerState extends State<_ChatModePicker> {
Widget _cupertinoSheet(BuildContext context) {
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
final modes = _modes;
final modes = _visibleModes;
final loaded = _modes != null;
return CupertinoActionSheet(
key: const Key('chat-mode-sheet'),
title: const Text('Mode'),
@@ -285,11 +312,11 @@ class _ChatModePickerState extends State<_ChatModePicker> {
color: CupertinoColors.systemRed.resolveFrom(context),
),
)
: modes == null
: !loaded
? const CupertinoActivityIndicator()
: null,
actions: [
for (final mode in modes ?? const <_Mode>[])
for (final mode in modes)
CupertinoActionSheetAction(
key: ValueKey<String>('chat-mode-option-${mode.id}'),
onPressed: () => _choose(mode),