Share one list row across runs, pipelines, chat, search and schedules

AppListRow (Material + Cupertino) with avatar, bold title and trailing
time, one muted line, one overflow menu style, inset dividers, selected
and emphasised states and a compact mode. Pipelines get a legible initial
avatar, schedule rows shrink to two lines with Edit/Pause/Delete in an
overflow menu, and the shell chat list scrolls behind the bar.
This commit is contained in:
2026-10-31 04:15:01 +00:00
parent 6ab8551348
commit 3c56db37fd
38 changed files with 1841 additions and 1520 deletions
@@ -5,6 +5,7 @@ import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'session_row_style.dart';
import '../../../../ui/layout/app_overflow_menu.dart';
enum SessionAction { star, rename, close, reopen, hide }
@@ -29,54 +30,19 @@ class SessionActionsButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final label = sessionActionsLabel(session, duplicateTitles);
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
// Its own node, so the row's merged label never swallows the button.
return Semantics(
container: true,
label: label,
button: true,
child: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: () => _showSheet(context),
child: const Icon(CupertinoIcons.ellipsis),
),
);
}
return PopupMenuButton<SessionAction>(
tooltip: label,
onSelected: onSelected,
itemBuilder: (context) => _menuItems(session),
return AppOverflowMenu<SessionAction>(
cupertino: chatControlsStyleOf(context) == ChatControlsStyle.cupertino,
label: sessionActionsLabel(session, duplicateTitles),
sheetTitle: chatSessionTitle(session),
actions: [
for (final item in _items(session))
AppMenuAction(value: item.action, label: item.label),
],
onSelected: (_, action) => onSelected(action),
);
}
Future<void> _showSheet(BuildContext context) async {
final action = await showCupertinoModalPopup<SessionAction>(
context: context,
builder: (sheetContext) => CupertinoActionSheet(
title: Text(chatSessionTitle(session)),
actions: [
for (final item in _items(session))
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(sheetContext, item.action),
child: Text(item.label),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(sheetContext),
child: const Text('Cancel'),
),
),
);
if (action != null && context.mounted) onSelected(action);
}
}
List<PopupMenuEntry<SessionAction>> _menuItems(JsonMap session) => [
for (final item in _items(session))
PopupMenuItem(value: item.action, child: Text(item.label)),
];
List<({SessionAction action, String label})> _items(JsonMap session) {
final isClosed = session['closed_at'] != null;
return [
@@ -1,5 +1,4 @@
import '../../../../ui/layout/collapsible_list_section.dart';
import '../../../../ui/theme/app_theme.dart';
import 'package:flutter/cupertino.dart';
import '../../../../core/api_gateway.dart';
@@ -8,7 +7,6 @@ import 'chat_adaptive.dart';
import 'chat_sessions_body.dart';
import 'session_actions.dart';
import 'session_row_content.dart';
import 'session_row_style.dart';
import '../../../../ui/adaptive/floating_bar_layout.dart';
class CupertinoSessionList extends StatelessWidget {
@@ -76,43 +74,45 @@ class CupertinoSessionList extends StatelessWidget {
count: section.sessions.length,
initiallyOpen: section.title != 'Closed',
children: [
for (final group in groups)
CupertinoListSection.insetGrouped(
backgroundColor: AppColors.groupedBackground,
header: groups.length > 1
? Text(
group.directory.isEmpty
? 'No directory'
: group.directory,
)
: null,
children: [
for (final session in group.sessions) ..._row(session),
],
),
for (final group in groups) ...[
if (groups.length > 1)
_DirectoryHeader(
group.directory.isEmpty ? 'No directory' : group.directory,
),
for (var i = 0; i < group.sessions.length; i++)
..._row(
group.sessions[i],
divider: i < group.sessions.length - 1,
),
],
],
),
];
}
/// The tile plus its refusal. `CupertinoListTile` forces its subtitle to one
/// ellipsised line, so the server's words go in their own full-width row
/// inside the same native card.
List<Widget> _row(JsonMap session) {
/// The row plus its refusal, the server's words in their own full-width
/// row under it.
List<Widget> _row(JsonMap session, {required bool divider}) {
final id = '${session['id'] ?? ''}';
final error = errorFor(id);
return [
_CupertinoSessionRow(
ChatSessionRow(
session: session,
selected: id == activeSessionId,
duplicateTitles: duplicateTitles,
unseen: isUnseen(session),
// A refusal below the row separates it instead.
divider: divider && error == null,
onOpen: onOpen,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onStar: onStar,
onHide: onHide,
onAction: (action) => _dispatch(
action,
session,
onStar: onStar,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onHide: onHide,
),
),
if (error != null)
ChatRowError(
@@ -124,101 +124,50 @@ class CupertinoSessionList extends StatelessWidget {
}
}
class _CupertinoSessionRow extends StatelessWidget {
const _CupertinoSessionRow({
required this.session,
required this.selected,
required this.duplicateTitles,
required this.unseen,
required this.onOpen,
required this.onRename,
required this.onClose,
required this.onReopen,
required this.onStar,
required this.onHide,
});
/// Routes a row's menu choice to the list's callbacks.
void _dispatch(
SessionAction action,
JsonMap session, {
required ValueChanged<JsonMap> onStar,
required ValueChanged<JsonMap> onRename,
required ValueChanged<JsonMap> onClose,
required ValueChanged<JsonMap> onReopen,
required ValueChanged<JsonMap> onHide,
}) {
switch (action) {
case SessionAction.star:
onStar(session);
case SessionAction.rename:
onRename(session);
case SessionAction.close:
onClose(session);
case SessionAction.reopen:
onReopen(session);
case SessionAction.hide:
onHide(session);
}
}
final JsonMap session;
final bool selected;
final Set<String> duplicateTitles;
final bool unseen;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
final ValueChanged<JsonMap> onStar;
final ValueChanged<JsonMap> onHide;
/// A directory's name above its chats, like a grouped table's header.
class _DirectoryHeader extends StatelessWidget {
const _DirectoryHeader(this.directory);
final String directory;
@override
Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}';
final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
// A contact-list row, the same pieces as the Material row. The grouped
// list owns the separators and the tile its native text styles; the
// leading slot is widened to hold the avatar.
// A narrow pane (a wide window's list beside its detail, or its opening
// animation) drops the avatar and tightens the tile's insets, so the
// menu stays reachable and the title keeps some width.
return LayoutBuilder(
builder: (context, constraints) {
final avatar = constraints.maxWidth >= _avatarMinWidth;
return Semantics(
selected: selected,
child: CupertinoListTile(
key: Key('chat-row-$id'),
backgroundColor: selected
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: null,
padding: avatar
? null
: const EdgeInsetsDirectional.only(start: 8, end: 4),
leadingSize: avatar ? 40 : 28,
leading: avatar
? ChatSessionAvatar(
session: session,
running: session['running'] == true && !unseen,
selected: selected,
)
: null,
title: ChatSessionTitleLine(
title: chatSessionTitle(session),
recency: relativeChatSessionTime(session['updated_at']),
unread: unseen && !closed,
starred: session['starred'] == true,
),
subtitle: ChatSessionSubtitleLine(
text: chatSessionSubtitle(session),
unread: unseen && !closed,
closed: closed,
),
trailing: SessionActionsButton(
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: _select,
),
onTap: () => onOpen(session),
),
);
},
final style = CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 13,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 6),
child: Text(
directory,
style: style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
);
}
/// The tile width below which the row is compact: no avatar, tight insets.
static const double _avatarMinWidth = 240;
void _select(SessionAction action) {
switch (action) {
case SessionAction.star:
onStar(session);
case SessionAction.rename:
onRename(session);
case SessionAction.close:
onClose(session);
case SessionAction.reopen:
onReopen(session);
case SessionAction.hide:
onHide(session);
}
}
}
@@ -8,7 +8,6 @@ import 'chat_adaptive.dart';
import 'chat_sessions_body.dart';
import 'session_actions.dart';
import 'session_row_content.dart';
import 'session_row_style.dart';
class MaterialSessionList extends StatelessWidget {
const MaterialSessionList({
@@ -83,35 +82,38 @@ class MaterialSessionList extends StatelessWidget {
style: heading.title.copyWith(fontWeight: FontWeight.w600),
),
),
// Material's native list separator between rows in a group, the
// counterpart of the inset group's hairline on Cupertino. The group
// header still owns the boundary between directories.
for (var i = 0; i < group.sessions.length; i++) ...[
if (i > 0) const Divider(height: 1),
..._row(group.sessions[i]),
],
// Inset dividers between the rows of a group; the group header
// owns the boundary between directories.
for (var i = 0; i < group.sessions.length; i++)
..._row(group.sessions[i], divider: i < group.sessions.length - 1),
],
],
);
}
/// The tile plus its refusal at full width (a long sentence in `subtitle`
/// The row plus its refusal at full width (a long sentence in a subtitle
/// made the row taller than the viewport at 320px with 2x text).
List<Widget> _row(JsonMap session) {
List<Widget> _row(JsonMap session, {required bool divider}) {
final id = '${session['id'] ?? ''}';
final error = errorFor(id);
return [
_MaterialSessionRow(
ChatSessionRow(
session: session,
selected: id == activeSessionId,
duplicateTitles: duplicateTitles,
unseen: isUnseen(session),
// A refusal below the row separates it instead.
divider: divider && error == null,
onOpen: onOpen,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onStar: onStar,
onHide: onHide,
onAction: (action) => _dispatch(
action,
session,
onStar: onStar,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onHide: onHide,
),
),
if (error != null)
ChatRowError(
@@ -123,99 +125,26 @@ class MaterialSessionList extends StatelessWidget {
}
}
class _MaterialSessionRow extends StatelessWidget {
const _MaterialSessionRow({
required this.session,
required this.selected,
required this.duplicateTitles,
required this.unseen,
required this.onOpen,
required this.onRename,
required this.onClose,
required this.onReopen,
required this.onStar,
required this.onHide,
});
final JsonMap session;
final bool selected;
final Set<String> duplicateTitles;
final bool unseen;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
final ValueChanged<JsonMap> onStar;
final ValueChanged<JsonMap> onHide;
@override
Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}';
final theme = Theme.of(context);
final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
// A contact-list row, the same pieces as the Cupertino row: the harness
// avatar, the title with its time, one muted line, and the actions menu.
// ListTile asserts when its trailing control leaves the title no width.
// A narrow pane (a wide window's list beside its detail, or its opening
// animation) drops the avatar and tightens the tile's insets, so the
// menu stays reachable and the title keeps some width.
return LayoutBuilder(
builder: (context, constraints) {
final narrow = constraints.maxWidth < _avatarMinWidth;
return ListTile(
key: Key('chat-row-$id'),
selected: selected,
selectedTileColor: theme.colorScheme.secondaryContainer,
selectedColor: theme.colorScheme.onSecondaryContainer,
contentPadding: narrow
? const EdgeInsetsDirectional.only(start: 8)
: null,
horizontalTitleGap: narrow ? 4 : null,
leading: narrow
? null
: ChatSessionAvatar(
session: session,
running: session['running'] == true && !unseen,
selected: selected,
),
title: ChatSessionTitleLine(
title: chatSessionTitle(session),
recency: relativeChatSessionTime(session['updated_at']),
unread: unseen && !closed,
starred: session['starred'] == true,
),
subtitle: ChatSessionSubtitleLine(
text: chatSessionSubtitle(session),
unread: unseen && !closed,
closed: closed,
),
trailing: SessionActionsButton(
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: _select,
),
onTap: () => onOpen(session),
);
},
);
}
/// The tile width below which the row is compact: no avatar, tight insets.
static const double _avatarMinWidth = 240;
void _select(SessionAction action) {
switch (action) {
case SessionAction.star:
onStar(session);
case SessionAction.rename:
onRename(session);
case SessionAction.close:
onClose(session);
case SessionAction.reopen:
onReopen(session);
case SessionAction.hide:
onHide(session);
}
/// Routes a row's menu choice to the list's callbacks.
void _dispatch(
SessionAction action,
JsonMap session, {
required ValueChanged<JsonMap> onStar,
required ValueChanged<JsonMap> onRename,
required ValueChanged<JsonMap> onClose,
required ValueChanged<JsonMap> onReopen,
required ValueChanged<JsonMap> onHide,
}) {
switch (action) {
case SessionAction.star:
onStar(session);
case SessionAction.rename:
onRename(session);
case SessionAction.close:
onClose(session);
case SessionAction.reopen:
onReopen(session);
case SessionAction.hide:
onHide(session);
}
}
@@ -2,12 +2,134 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../../../ui/layout/app_list_avatar.dart';
import '../../../../ui/layout/app_list_row.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'session_actions.dart';
import 'session_harness_icon.dart';
import 'session_row_style.dart';
/// Row pieces shared by the Material and Cupertino chat lists. Each list puts
/// them in its native tile's slots: the avatar leads, the title line and the
/// subtitle line fill the text column, and the actions menu trails.
/// One chat in the list, in the app's shared row on both hosts: the harness
/// avatar, the title with its recency, one muted line, and the actions menu.
///
/// 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 narrow pane drops
/// the avatar and time but keeps the menu, the list's only way to its actions.
class ChatSessionRow extends StatelessWidget {
const ChatSessionRow({
super.key,
required this.session,
required this.onOpen,
required this.onAction,
this.selected = false,
this.unseen = false,
this.divider = true,
this.duplicateTitles = const {},
});
final JsonMap session;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<SessionAction> onAction;
final bool selected;
final bool unseen;
final bool divider;
final Set<String> duplicateTitles;
@override
Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}';
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
final unread = unseen && !closed;
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final text = chatSessionSubtitle(session);
return AppListRow(
key: Key('chat-row-$id'),
cupertino: cupertino,
selected: selected,
emphasized: unread,
divider: divider,
keepMenuWhenCompact: true,
onTap: () => onOpen(session),
leading: ChatSessionAvatar(
session: session,
running: session['running'] == true && !unseen,
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),
),
),
],
),
),
time: relativeChatSessionTime(session['updated_at']),
// `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: SessionActionsButton(
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: onAction,
),
);
}
}
/// As tall as the title's text, so it follows text scaling.
class _Star extends StatelessWidget {
const _Star({required this.cupertino, required this.color});
final bool cupertino;
final Color color;
@override
Widget build(BuildContext context) {
final size = DefaultTextStyle.of(context).style.fontSize ?? 14;
return Icon(
cupertino ? CupertinoIcons.star_fill : Icons.star,
key: const Key('chat-row-starred'),
size: MediaQuery.textScalerOf(context).scale(size),
color: color,
semanticLabel: 'Starred',
);
}
}
/// The chat's harness mark in a filled circle, like a contact avatar. A
/// running chat carries a small activity badge on the avatar's corner instead
@@ -43,26 +165,18 @@ class ChatSessionAvatar extends StatelessWidget {
: scheme.surfaceContainerHighest;
mark = selected ? scheme.onPrimaryContainer : scheme.onSurfaceVariant;
}
final avatar = CircleAvatar(
backgroundColor: fill,
return AppListAvatar(
foreground: mark,
background: fill,
badge: running
? Semantics(
key: const Key('chat-row-working'),
label: 'Chat is working',
child: _WorkingBadge(cupertino: cupertino),
)
: null,
child: SessionHarnessIcon(session: session, color: mark),
);
if (!running) return avatar;
return Stack(
clipBehavior: Clip.none,
children: [
avatar,
PositionedDirectional(
end: -2,
bottom: -2,
child: Semantics(
key: const Key('chat-row-working'),
label: 'Chat is working',
child: _WorkingBadge(cupertino: cupertino),
),
),
],
);
}
}
@@ -90,152 +204,3 @@ class _WorkingBadge extends StatelessWidget {
);
}
}
/// The title with its recency at the trailing edge. An unread chat's title is
/// bold and its time takes the accent, so it stands out at a glance; a starred
/// chat shows a small star after its title.
class ChatSessionTitleLine extends StatelessWidget {
const ChatSessionTitleLine({
super.key,
required this.title,
required this.recency,
this.unread = false,
this.starred = false,
});
final String title;
final String recency;
final bool unread;
final bool starred;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final secondary = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final timeStyle =
(cupertino
? CupertinoTheme.of(context).textTheme.tabLabelTextStyle
: Theme.of(context).textTheme.bodySmall)
?.copyWith(
color: unread ? accent : secondary,
fontWeight: unread ? FontWeight.w600 : null,
);
final star = Icon(
cupertino ? CupertinoIcons.star_fill : Icons.star,
key: const Key('chat-row-starred'),
// As tall as the title's text, so it follows text scaling.
size: DefaultTextStyle.of(context).style.fontSize,
color: accent,
semanticLabel: 'Starred',
);
// The star rides in the title's own text, so a narrow row ellipsises
// them together; the time keeps at most about half the line.
return LayoutBuilder(
builder: (context, constraints) => Row(
children: [
Expanded(
child: Text.rich(
TextSpan(
text: title,
children: [
if (starred)
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: star,
),
),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: unread ? FontWeight.w700 : FontWeight.w500,
),
),
),
if (recency.isNotEmpty)
ConstrainedBox(
constraints: BoxConstraints(maxWidth: constraints.maxWidth / 2),
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 8),
child: Text(
recency,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: timeStyle,
),
),
),
],
),
);
}
}
/// One muted line: `Closed` first when the chat is closed, then the model and
/// folder, with an accent dot at the end while the chat has unread content.
class ChatSessionSubtitleLine extends StatelessWidget {
const ChatSessionSubtitleLine({
super.key,
required this.text,
this.unread = false,
this.closed = false,
});
final String text;
final bool unread;
final bool closed;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
return Row(
children: [
Expanded(
child: 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),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
if (unread)
Padding(
padding: const EdgeInsetsDirectional.only(start: 8),
child: Semantics(
key: const Key('chat-row-unread'),
label: 'New',
child: DecoratedBox(
decoration: BoxDecoration(
color: accent,
shape: BoxShape.circle,
),
child: const SizedBox.square(dimension: 10),
),
),
),
],
);
}
}