Resize chat list into compact rail and animate visible chat markers

This commit is contained in:
2026-11-07 13:20:12 +00:00
parent 19958e81c5
commit e2cfa90776
20 changed files with 555 additions and 173 deletions
@@ -20,6 +20,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
ChatSidebarMode _sidebarMode = ChatSidebarMode.expanded;
void _setSidebarMode(ChatSidebarMode mode) {
if (_sidebarMode == mode) return;
setState(() => _sidebarMode = mode);
_workspaceBinding?.changed();
}
@@ -43,6 +44,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
controller: _sessionsForSidebar,
folds: _foldsForSidebar,
activeSessionId: selected,
visibleSessionIds: _visibleSidebarSessions,
onOpen: _openSidebarSession,
onExpand: () => _setSidebarMode(ChatSidebarMode.expanded),
),
@@ -50,6 +52,21 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
);
}
Set<String> _visibleWorkspaceSessions = const {};
void _workspaceVisibilityChanged(Set<String> sessions) {
if (!mounted || setEquals(_visibleWorkspaceSessions, sessions)) return;
setState(() => _visibleWorkspaceSessions = Set.unmodifiable(sessions));
}
Set<String> get _visibleSidebarSessions {
if (!_workspaceVisible) return const {};
final retained = _workspace.panes.map((pane) => pane.sessionId).toSet();
final visible = _visibleWorkspaceSessions.intersection(retained);
final active = _workspace.activePane?.sessionId;
return visible.isNotEmpty ? visible : {?active};
}
ChatSessionsController get _sessionsForSidebar;
ChatSectionFolds get _foldsForSidebar;
void _openSidebarSession(JsonMap session);
@@ -72,6 +89,11 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
_sidebarMode = ChatSidebarMode.values.firstWhere(
(mode) => mode.name == snapshot.sidebarMode,
);
// Older snapshots could hide the rail. Keep their recovery affordance
// now that layout changes happen at the divider instead of a menu.
if (_sidebarMode == ChatSidebarMode.hidden) {
_sidebarMode = ChatSidebarMode.compact;
}
_usedWorkspace = true;
_workspaceVisible = _workspace.paneCount > 0;
});
+8 -4
View File
@@ -6,6 +6,7 @@ import '../../shell/list_detail.dart';
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show setEquals;
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
@@ -446,10 +447,6 @@ class _ChatScreenState extends State<ChatScreen>
showBackButton: pane == null
? null
: _page.open || !showsListBesideDetail(context),
sidebarControl:
pane == null || _page.open || !showsListBesideDetail(context)
? null
: ChatSidebarButton(mode: _sidebarMode, onChanged: _setSidebarMode),
paneControls: pane == null
? const []
: [
@@ -519,6 +516,7 @@ class _ChatScreenState extends State<ChatScreen>
onShortcutOpen: _openByShortcut,
onSessions: _adoptRows,
activeSessionId: selected,
visibleSessionIds: _visibleSidebarSessions,
publishShellBar:
(selected == null ||
!beside ||
@@ -572,6 +570,12 @@ class _ChatScreenState extends State<ChatScreen>
hideNavigation: true,
child: ListDetailPanes(
list: list,
compactListWidth: selected == null ? null : ChatCompactSidebar.width,
onListCompactChanged: selected == null
? null
: (compact) => _setSidebarMode(
compact ? ChatSidebarMode.compact : ChatSidebarMode.expanded,
),
listWidthOverride: selected == null
? null
: switch (_sidebarMode) {
@@ -5,6 +5,9 @@ import '../../../../core/api_gateway.dart';
import '../../domain/chat_cycle.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import '../../domain/chat_colors.dart';
import 'chat_color_palette.dart';
import 'chat_visibility_marker.dart';
import 'chat_sessions_body.dart';
import 'chat_sessions_controller.dart';
@@ -15,12 +18,14 @@ class ChatCompactSidebar extends StatelessWidget {
required this.controller,
required this.folds,
required this.activeSessionId,
this.visibleSessionIds = const {},
required this.onOpen,
required this.onExpand,
});
final ChatSessionsController controller;
final ChatSectionFolds folds;
final String? activeSessionId;
final Set<String> visibleSessionIds;
final ValueChanged<JsonMap> onOpen;
final VoidCallback onExpand;
static const width = 72.0;
@@ -54,6 +59,45 @@ class ChatCompactSidebar extends StatelessWidget {
);
}
Widget _session(BuildContext context, JsonMap row) {
final id = '${row['id'] ?? ''}';
final selected = id == activeSessionId;
final color =
chatColorShade(context, chatSessionColor(row)) ??
(chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary);
return ChatVisibilityMarker(
sessionId: id,
color: color,
visible: visibleSessionIds.contains(id),
active: selected,
child: AnimatedContainer(
duration: MediaQuery.disableAnimationsOf(context)
? Duration.zero
: const Duration(milliseconds: 200),
color: color.withValues(alpha: selected ? .24 : .07),
child: _button(
context,
chatSessionTitle(row),
CircleAvatar(
foregroundColor: color,
backgroundColor: color.withValues(alpha: selected ? .26 : .12),
child: Text(
chatSessionTitle(row).characters.take(2).toString(),
style: TextStyle(fontWeight: selected ? FontWeight.bold : null),
),
),
() {
unawaited(controller.markOpened(row));
onOpen(row);
},
selected: selected,
),
),
);
}
@override
Widget build(BuildContext context) => Align(
alignment: AlignmentDirectional.topStart,
@@ -81,26 +125,7 @@ class ChatCompactSidebar extends StatelessWidget {
isOpen: folds.isOpen,
);
return ListView(
children: [
for (final row in rows)
_button(
context,
chatSessionTitle(row),
Text(
chatSessionTitle(row).characters.take(2).toString(),
style: TextStyle(
fontWeight: row['id'] == activeSessionId
? FontWeight.bold
: null,
),
),
() {
unawaited(controller.markOpened(row));
onOpen(row);
},
selected: row['id'] == activeSessionId,
),
],
children: [for (final row in rows) _session(context, row)],
);
},
),
@@ -45,6 +45,7 @@ class ChatSessionsBody extends StatelessWidget {
required this.errorFor,
this.folds,
this.activeSessionId,
this.visibleSessionIds = const {},
this.onDismissError,
this.selectionOnly = false,
this.emptyMessageOverride,
@@ -56,6 +57,7 @@ class ChatSessionsBody extends StatelessWidget {
final ChatSectionFolds? folds;
final List<JsonMap> sessions;
final String? activeSessionId;
final Set<String> visibleSessionIds;
final String query;
final bool loading;
final String? error;
@@ -94,6 +96,7 @@ class ChatSessionsBody extends StatelessWidget {
sections: sections,
folds: folds,
activeSessionId: activeSessionId,
visibleSessionIds: visibleSessionIds,
emptyMessage: visible.isEmpty ? emptyMessage : null,
duplicateTitles: duplicateTitles,
onOpen: onOpen,
@@ -116,6 +119,7 @@ class ChatSessionsBody extends StatelessWidget {
sections: sections,
folds: folds,
activeSessionId: activeSessionId,
visibleSessionIds: visibleSessionIds,
emptyMessage: visible.isEmpty ? emptyMessage : null,
duplicateTitles: duplicateTitles,
onOpen: onOpen,
@@ -37,6 +37,7 @@ class ChatSessionsScreen extends StatefulWidget {
this.localStore,
this.controller,
this.activeSessionId,
this.visibleSessionIds = const {},
this.publishShellBar,
this.folds,
});
@@ -66,6 +67,7 @@ class ChatSessionsScreen extends StatefulWidget {
/// The conversation open above this list, or null when the list is showing.
/// Pushed activity for it is being read, so it never raises a New mark.
final String? activeSessionId;
final Set<String> visibleSessionIds;
/// A pushed phone page owns separate chrome. Keep the underlying list's bar
/// ready without pretending its open conversation is unread/inactive.
@@ -285,6 +287,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
child: ChatSessionsBody(
sessions: _controller.sessions,
activeSessionId: widget.activeSessionId,
visibleSessionIds: widget.visibleSessionIds,
query: _search.text,
loading: _controller.loading,
error: _controller.error,
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
/// A chat's colour identifies it; this animated edge identifies where it is
/// visible. The active chat has a stronger edge in both list presentations.
class ChatVisibilityMarker extends StatelessWidget {
const ChatVisibilityMarker({
super.key,
required this.sessionId,
required this.color,
required this.visible,
required this.active,
required this.child,
});
final String sessionId;
final Color color;
final bool visible;
final bool active;
final Widget child;
@override
Widget build(BuildContext context) => Semantics(
label: active
? 'Active chat'
: visible
? 'Visible chat'
: null,
child: AnimatedContainer(
key: ValueKey('chat-visibility-$sessionId'),
duration: MediaQuery.disableAnimationsOf(context)
? Duration.zero
: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
foregroundDecoration: BoxDecoration(
border: BorderDirectional(
start: visible
? BorderSide(color: color, width: active ? 7 : 3)
: BorderSide.none,
),
),
child: child,
),
);
}
@@ -26,6 +26,7 @@ class CupertinoSessionList extends StatelessWidget {
required this.errorFor,
this.folds,
this.activeSessionId,
this.visibleSessionIds = const {},
this.onDismissError,
this.selectionOnly = false,
});
@@ -34,6 +35,7 @@ class CupertinoSessionList extends StatelessWidget {
final bool selectionOnly;
final ChatSectionFolds? folds;
final String? activeSessionId;
final Set<String> visibleSessionIds;
final String? emptyMessage;
final Set<String> duplicateTitles;
final ValueChanged<JsonMap> onOpen;
@@ -88,6 +90,7 @@ class CupertinoSessionList extends StatelessWidget {
selectionOnly: selectionOnly,
divider: divider,
activeSessionId: activeSessionId,
visibleSessionIds: visibleSessionIds,
duplicateTitles: duplicateTitles,
isUnseen: isUnseen,
onOpen: onOpen,
@@ -83,6 +83,7 @@ SessionListItem chatSessionRowItem(
JsonMap session, {
required bool divider,
required String? activeSessionId,
Set<String> visibleSessionIds = const {},
required Set<String> duplicateTitles,
required bool Function(JsonMap) isUnseen,
required ValueChanged<JsonMap> onOpen,
@@ -103,6 +104,7 @@ SessionListItem chatSessionRowItem(
session: session,
selectionOnly: selectionOnly,
selected: id == activeSessionId,
visible: visibleSessionIds.contains(id),
duplicateTitles: duplicateTitles,
unseen: isUnseen(session),
divider: divider,
@@ -25,6 +25,7 @@ class MaterialSessionList extends StatelessWidget {
required this.errorFor,
this.folds,
this.activeSessionId,
this.visibleSessionIds = const {},
this.onDismissError,
this.selectionOnly = false,
});
@@ -33,6 +34,7 @@ class MaterialSessionList extends StatelessWidget {
final bool selectionOnly;
final ChatSectionFolds? folds;
final String? activeSessionId;
final Set<String> visibleSessionIds;
final String? emptyMessage;
final Set<String> duplicateTitles;
final ValueChanged<JsonMap> onOpen;
@@ -104,6 +106,7 @@ class MaterialSessionList extends StatelessWidget {
selectionOnly: selectionOnly,
divider: divider,
activeSessionId: activeSessionId,
visibleSessionIds: visibleSessionIds,
duplicateTitles: duplicateTitles,
isUnseen: isUnseen,
onOpen: onOpen,
@@ -10,6 +10,7 @@ import '../../domain/chat_list_activity.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'chat_color_palette.dart';
import 'chat_visibility_marker.dart';
import 'session_actions.dart';
import 'session_activity_badge.dart';
import 'session_harness_icon.dart';
@@ -21,9 +22,9 @@ import 'session_row_style.dart';
/// An unread chat is emphasised (heavier title, accent time) with an accent
/// dot ending its line; a starred chat shows a small star after its title; a
/// running chat carries an activity badge on its avatar. A chat with a colour
/// wears it as a bar on the row's leading edge, a faint row tint and a
/// coloured avatar. A narrow pane drops the avatar and time but keeps the
/// colour bar and the menu, the list's only way to its actions.
/// wears a faint row tint and a coloured avatar. An animated leading edge
/// marks visible chats, growing wider for the active chat. The menu remains
/// the row's way to its actions.
class ChatSessionRow extends StatelessWidget {
const ChatSessionRow({
super.key,
@@ -33,6 +34,7 @@ class ChatSessionRow extends StatelessWidget {
this.onOpenBelow,
required this.onAction,
this.selected = false,
this.visible = false,
this.unseen = false,
this.divider = true,
this.duplicateTitles = const {},
@@ -41,6 +43,7 @@ class ChatSessionRow extends StatelessWidget {
});
final JsonMap session;
/// A choosing surface keeps the normal row content but offers only opening.
final bool selectionOnly;
final ValueChanged<JsonMap> onOpen;
@@ -49,6 +52,7 @@ class ChatSessionRow extends StatelessWidget {
final VoidCallback? onLongPress;
final ValueChanged<SessionAction> onAction;
final bool selected;
final bool visible;
final bool unseen;
final bool divider;
final Set<String> duplicateTitles;
@@ -65,75 +69,82 @@ class ChatSessionRow extends StatelessWidget {
: Theme.of(context).colorScheme.primary;
final text = chatSessionSubtitle(session);
final updatedAt = _chatSessionInstant(session['updated_at']);
return AppListRow(
key: Key('chat-row-$id'),
cupertino: cupertino,
selected: selected,
emphasized: unread,
divider: divider,
onTap: () => onOpen(session),
onLongPress: selectionOnly ? null : onLongPress,
accent: chatColorShade(context, chatSessionColor(session)),
leading: ChatSessionAvatar(
session: session,
running: session['running'] == true && !unseen,
backgroundTasks: session['running'] == true
? 0
: chatSessionBackgroundTasks(session),
return ChatVisibilityMarker(
sessionId: id,
color: chatColorShade(context, chatSessionColor(session)) ?? accent,
visible: visible,
active: selected,
child: AppListRow(
key: Key('chat-row-$id'),
cupertino: cupertino,
selected: selected,
),
// The star rides in the title's own text, so a narrow row ellipsises
// them together.
title: Text.rich(
TextSpan(
text: chatSessionTitle(session),
children: [
if (session['starred'] == true)
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: _Star(cupertino: cupertino, color: accent),
emphasized: unread,
divider: divider,
onTap: () => onOpen(session),
onLongPress: selectionOnly ? null : onLongPress,
accent: chatColorShade(context, chatSessionColor(session)),
showAccentBorder: false,
leading: ChatSessionAvatar(
session: session,
running: session['running'] == true && !unseen,
backgroundTasks: session['running'] == true
? 0
: chatSessionBackgroundTasks(session),
selected: selected,
),
// The star rides in the title's own text, so a narrow row ellipsises
// them together.
title: Text.rich(
TextSpan(
text: chatSessionTitle(session),
children: [
if (session['starred'] == true)
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: _Star(cupertino: cupertino, color: accent),
),
),
),
],
],
),
),
),
timeWidget: updatedAt == null
? null
: RelativeTimeLabel(instant: updatedAt),
// `Closed` leads the line of a closed chat, then the model and folder.
subtitle: Text.rich(
TextSpan(
children: [
if (closed)
const TextSpan(
text: 'Closed',
style: TextStyle(fontWeight: FontWeight.w600),
),
if (closed && text.isNotEmpty) const TextSpan(text: ' · '),
TextSpan(text: text),
],
timeWidget: updatedAt == null
? null
: RelativeTimeLabel(instant: updatedAt),
// `Closed` leads the line of a closed chat, then the model and folder.
subtitle: Text.rich(
TextSpan(
children: [
if (closed)
const TextSpan(
text: 'Closed',
style: TextStyle(fontWeight: FontWeight.w600),
),
if (closed && text.isNotEmpty) const TextSpan(text: ' · '),
TextSpan(text: text),
],
),
),
subtitleTrailing: unread
? AppListStatusDot(
key: const Key('chat-row-unread'),
color: accent,
semanticLabel: 'New',
size: 10,
)
: null,
menu: selectionOnly
? null
: SessionActionsButton(
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: onAction,
allowOpenBeside: onOpenBeside != null,
allowOpenBelow: onOpenBelow != null,
),
),
subtitleTrailing: unread
? AppListStatusDot(
key: const Key('chat-row-unread'),
color: accent,
semanticLabel: 'New',
size: 10,
)
: null,
menu: selectionOnly
? null
: SessionActionsButton(
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: onAction,
allowOpenBeside: onOpenBeside != null,
allowOpenBelow: onOpenBelow != null,
),
);
}
}
@@ -15,6 +15,7 @@ Widget memoChatSessionRow({
required JsonMap session,
bool selectionOnly = false,
required bool selected,
bool visible = false,
required Set<String> duplicateTitles,
required bool unseen,
required bool divider,
@@ -33,6 +34,7 @@ Widget memoChatSessionRow({
MemoMap(session),
selectionOnly,
selected,
visible,
// The row reads the set only for its own title.
duplicateTitles.contains(chatSessionTitle(session)),
unseen,
@@ -51,6 +53,7 @@ Widget memoChatSessionRow({
session: session,
selectionOnly: selectionOnly,
selected: selected,
visible: visible,
duplicateTitles: duplicateTitles,
unseen: unseen,
divider: divider,