Restore local chat layouts and add compact or hidden chat sidebar

This commit is contained in:
2026-11-06 19:16:18 +00:00
parent 8a7b704940
commit 9a0d5de26a
9 changed files with 834 additions and 16 deletions
@@ -0,0 +1,83 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../ui/sessions/chat_adaptive.dart';
enum ChatSidebarMode { expanded, compact, hidden }
/// Pinned rather than overflowed: the list can always be restored from a pane.
class ChatSidebarButton extends StatelessWidget {
const ChatSidebarButton({
super.key,
required this.mode,
required this.onChanged,
});
final ChatSidebarMode mode;
final ValueChanged<ChatSidebarMode> onChanged;
Future<void> _choose(BuildContext context) async {
final ChatSidebarMode? choice;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
choice = await showCupertinoModalPopup<ChatSidebarMode>(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('Chat list'),
actions: [
for (final value in ChatSidebarMode.values)
CupertinoActionSheetAction(
isDefaultAction: mode == value,
onPressed: () => Navigator.pop(context, value),
child: Text(_label(value)),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
} else {
choice = await showDialog<ChatSidebarMode>(
context: context,
builder: (context) => SimpleDialog(
title: const Text('Chat list'),
children: [
for (final value in ChatSidebarMode.values)
SimpleDialogOption(
onPressed: () => Navigator.pop(context, value),
child: Row(
children: [
Expanded(child: Text(_label(value))),
if (value == mode) const Icon(Icons.check),
],
),
),
],
),
);
}
if (choice != null && context.mounted) onChanged(choice);
}
static String _label(ChatSidebarMode value) => switch (value) {
ChatSidebarMode.expanded => 'Expanded chat list',
ChatSidebarMode.compact => 'Compact chat list',
ChatSidebarMode.hidden => 'Hide chat list',
};
@override
Widget build(BuildContext context) =>
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? Semantics(
label: 'Chat list layout',
button: true,
child: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: () => _choose(context),
child: const Icon(CupertinoIcons.sidebar_left),
),
)
: IconButton(
tooltip: 'Chat list layout',
onPressed: () => _choose(context),
icon: const Icon(Icons.view_sidebar_outlined),
);
}
@@ -91,6 +91,7 @@ class ChatThreadView extends StatefulWidget {
this.onColorSelected,
this.onNextChat,
this.paneControls = const [],
this.sidebarControl,
this.showBackButton,
});
@@ -100,6 +101,7 @@ class ChatThreadView extends StatefulWidget {
/// the bar's Next chat button; null when there is no other chat to open.
final VoidCallback? onNextChat;
final List<Widget> paneControls;
final Widget? sidebarControl;
final bool? showBackButton;
/// Sets the chat's shared colour (a palette name, null for none) from the
@@ -1206,6 +1208,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
// would take more than half the pill. A session without a mode draws
// no mode control, so no empty pill is ever drawn.
controls: [
?widget.sidebarControl,
...widget.paneControls,
if (hasModel)
ChatModelControl(