Merge commit 'bd256ad1'
This commit is contained in:
@@ -148,12 +148,13 @@ class _CupertinoSessionRow extends StatelessWidget {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
// Cupertino's grouped list owns the separators and the native tile metrics;
|
||||
// the row only decides where the title, its state word and the muted meta
|
||||
// go. The meta line (recency first) keeps the tile's native 12pt style by
|
||||
// go. Each metadata line keeps the tile's native 12pt style by
|
||||
// passing colour only, so `Text` merges with `CupertinoListTile`'s own
|
||||
// `DefaultTextStyle` instead of overriding it with the title's size.
|
||||
final theme = CupertinoTheme.of(context);
|
||||
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||
final meta = chatSessionRowMetaLine(session);
|
||||
final meta = chatSessionMetaLines(session);
|
||||
final recency = relativeChatSessionTime(session['updated_at']);
|
||||
final status = chatSessionRowStatus(session, unseen: unseen);
|
||||
final statusStyle = TextStyle(
|
||||
color: status == 'Closed' ? secondary : theme.primaryColor,
|
||||
@@ -171,20 +172,18 @@ class _CupertinoSessionRow extends StatelessWidget {
|
||||
),
|
||||
// As on the web: the title with the unread/closed word trailing, then
|
||||
// the muted `recency · directory · model` line.
|
||||
title: ChatSessionRowMeta(
|
||||
meta: chatSessionTitle(session),
|
||||
title: ChatSessionRowContent(
|
||||
title: chatSessionTitle(session),
|
||||
status: status,
|
||||
metaStyle: const TextStyle(),
|
||||
recency: recency.isEmpty ? null : recency,
|
||||
meta: meta,
|
||||
titleStyle: theme.textTheme.textStyle.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
metaStyle: TextStyle(color: secondary),
|
||||
statusStyle: statusStyle,
|
||||
),
|
||||
subtitle: meta.isEmpty
|
||||
? null
|
||||
: Text(
|
||||
meta,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: secondary),
|
||||
),
|
||||
subtitle: null,
|
||||
onTap: () => onOpen(session),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
@@ -151,14 +151,15 @@ class _MaterialSessionRow extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
// The same content as the Cupertino row: title with the unread/closed word
|
||||
// trailing, then a muted `recency · directory · model` line.
|
||||
// The same content as the Cupertino row: title and state, then each
|
||||
// recorded metadata field on its own muted line.
|
||||
// `ListTile` does not force one ellipsised line like `CupertinoListTile`,
|
||||
// so both text widgets state their line limit themselves. The meta line
|
||||
// passes colour only, so it keeps the tile's native subtitle style.
|
||||
final theme = Theme.of(context);
|
||||
final secondary = theme.colorScheme.onSurfaceVariant;
|
||||
final meta = chatSessionRowMetaLine(session);
|
||||
final meta = chatSessionMetaLines(session);
|
||||
final recency = relativeChatSessionTime(session['updated_at']);
|
||||
final status = chatSessionRowStatus(session, unseen: unseen);
|
||||
final statusStyle = TextStyle(
|
||||
color: status == 'Closed' ? secondary : theme.colorScheme.primary,
|
||||
@@ -171,20 +172,18 @@ class _MaterialSessionRow extends StatelessWidget {
|
||||
leading: Icon(sessionMaterialIcon(session)),
|
||||
// As on the web: the title with the unread/closed word trailing, then
|
||||
// the muted `recency · directory · model` line.
|
||||
title: ChatSessionRowMeta(
|
||||
meta: chatSessionTitle(session),
|
||||
title: ChatSessionRowContent(
|
||||
title: chatSessionTitle(session),
|
||||
status: status,
|
||||
metaStyle: const TextStyle(),
|
||||
recency: recency.isEmpty ? null : recency,
|
||||
meta: meta,
|
||||
titleStyle:
|
||||
theme.textTheme.titleSmall ??
|
||||
const TextStyle(fontWeight: FontWeight.w600),
|
||||
metaStyle: TextStyle(color: secondary),
|
||||
statusStyle: statusStyle,
|
||||
),
|
||||
subtitle: meta.isEmpty
|
||||
? null
|
||||
: Text(
|
||||
meta,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: secondary),
|
||||
),
|
||||
subtitle: null,
|
||||
onTap: () => onOpen(session),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
@@ -1,83 +1,97 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// A chat session row line with the unread/closed word at its trailing edge:
|
||||
/// the row's title line, as on the web.
|
||||
///
|
||||
/// The directory/model is the part that ellipsises; the state word is the row's
|
||||
/// only unread marker, so it keeps its intrinsic width and the metadata shrinks
|
||||
/// first. If even the whole text column cannot hold the word at the current
|
||||
/// text scale it is scaled down rather than clipped, so `New`/`Closed` is never
|
||||
/// replaced by an ellipsis.
|
||||
class ChatSessionRowMeta extends StatelessWidget {
|
||||
const ChatSessionRowMeta({
|
||||
/// Hierarchical row copy shared by the Material and Cupertino list variants.
|
||||
/// Each server-recorded fact keeps its own line; recency is visually anchored
|
||||
/// at the end of its own line rather than competing with the other metadata.
|
||||
class ChatSessionRowContent extends StatelessWidget {
|
||||
const ChatSessionRowContent({
|
||||
super.key,
|
||||
required this.meta,
|
||||
required this.title,
|
||||
required this.status,
|
||||
required this.recency,
|
||||
required this.meta,
|
||||
required this.titleStyle,
|
||||
required this.metaStyle,
|
||||
required this.statusStyle,
|
||||
});
|
||||
|
||||
final String meta;
|
||||
final String title;
|
||||
final String? status;
|
||||
final String? recency;
|
||||
final List<String> meta;
|
||||
final TextStyle titleStyle;
|
||||
final TextStyle metaStyle;
|
||||
final TextStyle statusStyle;
|
||||
|
||||
/// The trailing word's intrinsic width is measured against the full text
|
||||
/// column, minus this gap, so the row can never overflow the line.
|
||||
static const _statusGap = 8.0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) => Row(
|
||||
children: [
|
||||
Expanded(
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: titleStyle,
|
||||
),
|
||||
if (status != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: _StatusLabel(status: status!, style: statusStyle),
|
||||
),
|
||||
],
|
||||
if (recency != null && recency!.isNotEmpty) ...[
|
||||
const SizedBox(height: 3),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: Text(
|
||||
meta,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
recency!,
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.end,
|
||||
style: metaStyle,
|
||||
),
|
||||
),
|
||||
if (status != null)
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: constraints.maxWidth),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: _statusGap),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: status == 'New'
|
||||
? _UnreadBadge(style: statusStyle)
|
||||
: Text(status!, maxLines: 1, style: statusStyle),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (final line in meta)
|
||||
Text(
|
||||
line,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: metaStyle,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A chat with messages not yet seen: the word in a filled pill.
|
||||
class _UnreadBadge extends StatelessWidget {
|
||||
const _UnreadBadge({required this.style});
|
||||
class _StatusLabel extends StatelessWidget {
|
||||
const _StatusLabel({required this.status, required this.style});
|
||||
|
||||
final String status;
|
||||
final TextStyle style;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = style.color ?? const Color(0xFF0A84FF);
|
||||
if (status != 'New') {
|
||||
return Text(
|
||||
status,
|
||||
maxLines: 2,
|
||||
style: style.copyWith(fontWeight: FontWeight.w600),
|
||||
);
|
||||
}
|
||||
final color = style.color ?? Theme.of(context).colorScheme.primary;
|
||||
return DecoratedBox(
|
||||
key: const Key('chat-row-unread'),
|
||||
decoration: ShapeDecoration(color: color, shape: const StadiumBorder()),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1),
|
||||
child: Text(
|
||||
'New',
|
||||
maxLines: 1,
|
||||
status,
|
||||
maxLines: 2,
|
||||
style: style.copyWith(
|
||||
color: const Color(0xFFFFFFFF),
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -43,16 +43,14 @@ String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) {
|
||||
return '${then.day} ${_shortMonths[then.month - 1]}';
|
||||
}
|
||||
|
||||
/// The row's muted second line: which agent runs the chat (an empty backend
|
||||
/// is a legacy OpenCode row), its model, and the directory with the home
|
||||
/// folder written as `~`.
|
||||
String chatSessionMeta(JsonMap session) {
|
||||
/// Recorded session fields rendered independently beneath the title.
|
||||
List<String> chatSessionMetaLines(JsonMap session) {
|
||||
final backend = '${session['backend'] ?? ''}'.trim();
|
||||
return [
|
||||
backend.isEmpty ? 'opencode' : backend,
|
||||
'${session['model'] ?? ''}'.trim(),
|
||||
homeRelativePath('${session['directory'] ?? ''}'.trim()),
|
||||
].where((part) => part.isNotEmpty).join(' · ');
|
||||
].where((part) => part.isNotEmpty).toList();
|
||||
}
|
||||
|
||||
final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)');
|
||||
@@ -60,12 +58,11 @@ final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)');
|
||||
/// `/Users/alan/repos/x` (or `/home/alan/...`) as `~/repos/x`.
|
||||
String homeRelativePath(String path) => path.replaceFirst(_homePrefix, '~');
|
||||
|
||||
/// The row's muted second line as the web words it: recency first, then the
|
||||
/// directory and model (`1 day ago · /srv/probe · model-a`).
|
||||
String chatSessionRowMetaLine(JsonMap session, {DateTime? now}) => [
|
||||
/// All secondary row information, each as a distinct line.
|
||||
List<String> chatSessionRowMetaLines(JsonMap session, {DateTime? now}) => [
|
||||
relativeChatSessionTime(session['updated_at'], now: now),
|
||||
chatSessionMeta(session),
|
||||
].where((part) => part.isNotEmpty).join(' · ');
|
||||
...chatSessionMetaLines(session),
|
||||
].where((part) => part.isNotEmpty).toList();
|
||||
|
||||
/// The word on the row's trailing edge while the session has news or a state:
|
||||
/// `Closed` from the row, otherwise `New`. A streaming session deliberately
|
||||
|
||||
Reference in New Issue
Block a user