fix(app): chat rows put the state word on the title line and recency in the meta, as on the web
This commit is contained in:
@@ -126,16 +126,13 @@ class _CupertinoSessionRow extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final id = '${session['id'] ?? ''}';
|
final id = '${session['id'] ?? ''}';
|
||||||
// Cupertino's grouped list owns the separators and the native tile metrics;
|
// Cupertino's grouped list owns the separators and the native tile metrics;
|
||||||
// the row only decides where the title, its muted meta and the recency go.
|
// the row only decides where the title, its state word and the muted meta
|
||||||
// The recency sits at the trailing edge of the title line at the tile's
|
// go. The meta line (recency first) keeps the tile's native 12pt style by
|
||||||
// body size; the meta line keeps the tile's native 12pt subtitle style by
|
|
||||||
// passing colour only, so `Text` merges with `CupertinoListTile`'s own
|
// passing colour only, so `Text` merges with `CupertinoListTile`'s own
|
||||||
// `DefaultTextStyle` instead of overriding it with the title's size.
|
// `DefaultTextStyle` instead of overriding it with the title's size.
|
||||||
final theme = CupertinoTheme.of(context);
|
final theme = CupertinoTheme.of(context);
|
||||||
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||||
final timeStyle = theme.textTheme.textStyle.copyWith(color: secondary);
|
final meta = chatSessionRowMetaLine(session);
|
||||||
final time = relativeChatSessionTime(session['updated_at']);
|
|
||||||
final meta = chatSessionMeta(session);
|
|
||||||
final status = chatSessionRowStatus(session, unseen: unseen);
|
final status = chatSessionRowStatus(session, unseen: unseen);
|
||||||
final statusStyle = TextStyle(
|
final statusStyle = TextStyle(
|
||||||
color: status == 'Closed' ? secondary : theme.primaryColor,
|
color: status == 'Closed' ? secondary : theme.primaryColor,
|
||||||
@@ -143,18 +140,21 @@ class _CupertinoSessionRow extends StatelessWidget {
|
|||||||
return CupertinoListTile(
|
return CupertinoListTile(
|
||||||
key: Key('chat-row-$id'),
|
key: Key('chat-row-$id'),
|
||||||
leading: Icon(sessionCupertinoIcon(session)),
|
leading: Icon(sessionCupertinoIcon(session)),
|
||||||
title: ChatSessionRowTitle(
|
// As on the web: the title with the unread/closed word trailing, then
|
||||||
title: chatSessionTitle(session),
|
// the muted `recency · directory · model` line.
|
||||||
time: time,
|
title: ChatSessionRowMeta(
|
||||||
timeStyle: timeStyle,
|
meta: chatSessionTitle(session),
|
||||||
|
status: status,
|
||||||
|
metaStyle: const TextStyle(),
|
||||||
|
statusStyle: statusStyle,
|
||||||
),
|
),
|
||||||
subtitle: meta.isEmpty && status == null
|
subtitle: meta.isEmpty
|
||||||
? null
|
? null
|
||||||
: ChatSessionRowMeta(
|
: Text(
|
||||||
meta: meta,
|
meta,
|
||||||
status: status,
|
maxLines: 1,
|
||||||
metaStyle: TextStyle(color: secondary),
|
overflow: TextOverflow.ellipsis,
|
||||||
statusStyle: statusStyle,
|
style: TextStyle(color: secondary),
|
||||||
),
|
),
|
||||||
onTap: () => onOpen(session),
|
onTap: () => onOpen(session),
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
|
|||||||
@@ -139,18 +139,14 @@ class _MaterialSessionRow extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final id = '${session['id'] ?? ''}';
|
final id = '${session['id'] ?? ''}';
|
||||||
// The same content as the Cupertino row: title with trailing recency, then
|
// The same content as the Cupertino row: title with the unread/closed word
|
||||||
// a muted `directory · model` line with the unread/closed word trailing.
|
// trailing, then a muted `recency · directory · model` line.
|
||||||
// `ListTile` does not force one ellipsised line like `CupertinoListTile`,
|
// `ListTile` does not force one ellipsised line like `CupertinoListTile`,
|
||||||
// so both text widgets state their line limit themselves. The meta line
|
// so both text widgets state their line limit themselves. The meta line
|
||||||
// passes colour only, so it keeps the tile's native subtitle style.
|
// passes colour only, so it keeps the tile's native subtitle style.
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final secondary = theme.colorScheme.onSurfaceVariant;
|
final secondary = theme.colorScheme.onSurfaceVariant;
|
||||||
final timeStyle =
|
final meta = chatSessionRowMetaLine(session);
|
||||||
theme.textTheme.bodyMedium?.copyWith(color: secondary) ??
|
|
||||||
TextStyle(color: secondary);
|
|
||||||
final time = relativeChatSessionTime(session['updated_at']);
|
|
||||||
final meta = chatSessionMeta(session);
|
|
||||||
final status = chatSessionRowStatus(session, unseen: unseen);
|
final status = chatSessionRowStatus(session, unseen: unseen);
|
||||||
final statusStyle = TextStyle(
|
final statusStyle = TextStyle(
|
||||||
color: status == 'Closed' ? secondary : theme.colorScheme.primary,
|
color: status == 'Closed' ? secondary : theme.colorScheme.primary,
|
||||||
@@ -158,18 +154,21 @@ class _MaterialSessionRow extends StatelessWidget {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
key: Key('chat-row-$id'),
|
key: Key('chat-row-$id'),
|
||||||
leading: Icon(sessionMaterialIcon(session)),
|
leading: Icon(sessionMaterialIcon(session)),
|
||||||
title: ChatSessionRowTitle(
|
// As on the web: the title with the unread/closed word trailing, then
|
||||||
title: chatSessionTitle(session),
|
// the muted `recency · directory · model` line.
|
||||||
time: time,
|
title: ChatSessionRowMeta(
|
||||||
timeStyle: timeStyle,
|
meta: chatSessionTitle(session),
|
||||||
|
status: status,
|
||||||
|
metaStyle: const TextStyle(),
|
||||||
|
statusStyle: statusStyle,
|
||||||
),
|
),
|
||||||
subtitle: meta.isEmpty && status == null
|
subtitle: meta.isEmpty
|
||||||
? null
|
? null
|
||||||
: ChatSessionRowMeta(
|
: Text(
|
||||||
meta: meta,
|
meta,
|
||||||
status: status,
|
maxLines: 1,
|
||||||
metaStyle: TextStyle(color: secondary),
|
overflow: TextOverflow.ellipsis,
|
||||||
statusStyle: statusStyle,
|
style: TextStyle(color: secondary),
|
||||||
),
|
),
|
||||||
onTap: () => onOpen(session),
|
onTap: () => onOpen(session),
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
|
|||||||
@@ -1,55 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// The title line of a chat session row: the session's name, with its relative
|
/// A chat session row line with the unread/closed word at its trailing edge:
|
||||||
/// recency at the trailing edge. Shared by the Material and Cupertino rows so
|
/// the row's title line, as on the web.
|
||||||
/// both hosts arrange the same facts the same way.
|
|
||||||
///
|
|
||||||
/// The recency takes at most 45% of the text column and ellipsises there, so a
|
|
||||||
/// long title keeps the larger share and a short row never overflows. The
|
|
||||||
/// recency is supplementary: at very large text scales it is the part that
|
|
||||||
/// gives way, while the session's name and state word stay whole.
|
|
||||||
class ChatSessionRowTitle extends StatelessWidget {
|
|
||||||
const ChatSessionRowTitle({
|
|
||||||
super.key,
|
|
||||||
required this.title,
|
|
||||||
required this.time,
|
|
||||||
required this.timeStyle,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
final String time;
|
|
||||||
final TextStyle timeStyle;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return LayoutBuilder(
|
|
||||||
builder: (context, constraints) => Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(title, maxLines: 1, overflow: TextOverflow.ellipsis),
|
|
||||||
),
|
|
||||||
if (time.isNotEmpty) ...[
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
ConstrainedBox(
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: constraints.maxWidth * 0.45,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
time,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: timeStyle,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The muted second line of a chat session row: the recorded directory and
|
|
||||||
/// model, with the unread/closed word at the trailing edge.
|
|
||||||
///
|
///
|
||||||
/// The directory/model is the part that ellipsises; the state word is the row's
|
/// 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
|
/// only unread marker, so it keeps its intrinsic width and the metadata shrinks
|
||||||
|
|||||||
@@ -50,6 +50,13 @@ String chatSessionMeta(JsonMap session) => [
|
|||||||
'${session['model'] ?? ''}'.trim(),
|
'${session['model'] ?? ''}'.trim(),
|
||||||
].where((part) => part.isNotEmpty).join(' · ');
|
].where((part) => part.isNotEmpty).join(' · ');
|
||||||
|
|
||||||
|
/// 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}) => [
|
||||||
|
relativeChatSessionTime(session['updated_at'], now: now),
|
||||||
|
chatSessionMeta(session),
|
||||||
|
].where((part) => part.isNotEmpty).join(' · ');
|
||||||
|
|
||||||
/// The word on the row's trailing edge while the session has news or a state:
|
/// 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
|
/// `Closed` from the row, otherwise `New`. A streaming session deliberately
|
||||||
/// says nothing, as on the web, where the row's activity logo carries it.
|
/// says nothing, as on the web, where the row's activity logo carries it.
|
||||||
|
|||||||
@@ -154,22 +154,27 @@ void main() {
|
|||||||
isUnseen: (session) => session['id'] == 's1',
|
isUnseen: (session) => session['id'] == 's1',
|
||||||
);
|
);
|
||||||
|
|
||||||
// The unread word trails the muted meta line; the recency trails the title.
|
// As on the web: the unread word trails the title; the muted meta line
|
||||||
|
// leads with the recency.
|
||||||
expect(find.text('Starred chat'), findsOneWidget);
|
expect(find.text('Starred chat'), findsOneWidget);
|
||||||
expect(find.text('/work · model-a'), findsOneWidget);
|
expect(find.text('5 min ago · /work · model-a'), findsOneWidget);
|
||||||
expect(find.text('5 min ago'), findsOneWidget);
|
|
||||||
expect(find.text('New'), findsOneWidget);
|
expect(find.text('New'), findsOneWidget);
|
||||||
expect(find.text('/work'), findsOneWidget);
|
expect(find.text('2 hr ago · /work'), findsOneWidget);
|
||||||
expect(find.text('2 hr ago'), findsOneWidget);
|
expect(
|
||||||
|
(tester.getCenter(find.text('Starred chat')).dy -
|
||||||
|
tester.getCenter(find.text('New')).dy)
|
||||||
|
.abs(),
|
||||||
|
lessThan(4),
|
||||||
|
);
|
||||||
|
|
||||||
// The meta line keeps `CupertinoListTile`'s native 12pt subtitle style; it
|
// The meta line keeps `CupertinoListTile`'s native 12pt subtitle style; it
|
||||||
// must not be rendered at the title's body size. The colour-only style the
|
// must not be rendered at the title's body size. The colour-only style the
|
||||||
// row passes merges with the tile's own `DefaultTextStyle`.
|
// row passes merges with the tile's own `DefaultTextStyle`.
|
||||||
final titleStyle = _styleOf(tester, 'Starred chat');
|
final titleStyle = _styleOf(tester, 'Starred chat');
|
||||||
final metaStyle = _styleOf(tester, '/work · model-a');
|
final metaStyle = _styleOf(tester, '5 min ago · /work · model-a');
|
||||||
expect(metaStyle.fontSize, lessThan(titleStyle.fontSize!));
|
expect(metaStyle.fontSize, lessThan(titleStyle.fontSize!));
|
||||||
expect(metaStyle.fontSize, 12.0);
|
expect(metaStyle.fontSize, 12.0);
|
||||||
expect(_styleOf(tester, 'New').fontSize, metaStyle.fontSize);
|
expect(_styleOf(tester, 'New').fontSize, titleStyle.fontSize);
|
||||||
|
|
||||||
// Each session is still its own native tile with its own actions, so the
|
// Each session is still its own native tile with its own actions, so the
|
||||||
// inset group draws the separator between them.
|
// inset group draws the separator between them.
|
||||||
@@ -210,7 +215,7 @@ void main() {
|
|||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
const title = 'A conversation title long enough to need an ellipsis';
|
const title = 'A conversation title long enough to need an ellipsis';
|
||||||
const meta =
|
const meta =
|
||||||
'/a/very/long/directory/that/must/ellipsise · '
|
'3 days ago · /a/very/long/directory/that/must/ellipsise · '
|
||||||
'provider/an-extremely-long-recorded-model-id';
|
'provider/an-extremely-long-recorded-model-id';
|
||||||
final titleParagraph = tester.renderObject<RenderParagraph>(
|
final titleParagraph = tester.renderObject<RenderParagraph>(
|
||||||
find.text(title),
|
find.text(title),
|
||||||
@@ -239,16 +244,10 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The recency is supplementary, so it is the part that ellipsises here; it
|
// The word shares the title's line, as on the web.
|
||||||
// still keeps its single line at the trailing edge of the title line.
|
|
||||||
final recency = tester.renderObject<RenderParagraph>(
|
|
||||||
find.text('3 days ago'),
|
|
||||||
);
|
|
||||||
expect(recency.maxLines, 1);
|
|
||||||
expect(recency.didExceedMaxLines, isTrue);
|
|
||||||
expect(
|
expect(
|
||||||
(tester.getCenter(find.text(title)).dy -
|
(tester.getCenter(find.text(title)).dy -
|
||||||
tester.getCenter(find.text('3 days ago')).dy)
|
tester.getCenter(find.text('New')).dy)
|
||||||
.abs(),
|
.abs(),
|
||||||
lessThan(20),
|
lessThan(20),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -73,15 +73,20 @@ void main() {
|
|||||||
], isUnseen: (session) => session['id'] == 's1');
|
], isUnseen: (session) => session['id'] == 's1');
|
||||||
|
|
||||||
expect(find.text('Starred chat'), findsOneWidget);
|
expect(find.text('Starred chat'), findsOneWidget);
|
||||||
expect(find.text('/work · model-a'), findsOneWidget);
|
expect(find.text('5 min ago · /work · model-a'), findsOneWidget);
|
||||||
expect(find.text('5 min ago'), findsOneWidget);
|
|
||||||
expect(find.text('New'), findsOneWidget);
|
expect(find.text('New'), findsOneWidget);
|
||||||
expect(find.text('/work'), findsOneWidget);
|
expect(find.text('2 hr ago · /work'), findsOneWidget);
|
||||||
expect(find.text('2 hr ago'), findsOneWidget);
|
// As on the web, the unread word shares the title's line.
|
||||||
|
expect(
|
||||||
|
(tester.getCenter(find.text('Starred chat')).dy -
|
||||||
|
tester.getCenter(find.text('New')).dy)
|
||||||
|
.abs(),
|
||||||
|
lessThan(4),
|
||||||
|
);
|
||||||
|
|
||||||
// The meta line is the theme's muted colour, not the title colour.
|
// The meta line is the theme's muted colour, not the title colour.
|
||||||
final meta = tester.widget<Text>(find.text('/work · model-a'));
|
final meta = tester.widget<Text>(find.text('5 min ago · /work · model-a'));
|
||||||
final context = tester.element(find.text('/work · model-a'));
|
final context = tester.element(find.text('5 min ago · /work · model-a'));
|
||||||
expect(meta.style?.color, Theme.of(context).colorScheme.onSurfaceVariant);
|
expect(meta.style?.color, Theme.of(context).colorScheme.onSurfaceVariant);
|
||||||
|
|
||||||
// Native Material separators sit between rows, not around the group.
|
// Native Material separators sit between rows, not around the group.
|
||||||
@@ -145,7 +150,7 @@ void main() {
|
|||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
const title = 'A conversation title long enough to need an ellipsis';
|
const title = 'A conversation title long enough to need an ellipsis';
|
||||||
const meta =
|
const meta =
|
||||||
'/a/very/long/directory/that/must/ellipsise · '
|
'3 days ago · /a/very/long/directory/that/must/ellipsise · '
|
||||||
'provider/an-extremely-long-recorded-model-id';
|
'provider/an-extremely-long-recorded-model-id';
|
||||||
final titleParagraph = tester.renderObject<RenderParagraph>(
|
final titleParagraph = tester.renderObject<RenderParagraph>(
|
||||||
find.text(title),
|
find.text(title),
|
||||||
@@ -173,7 +178,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two lines: the title/recency line, then the muted meta line.
|
// Two lines: the title/word line, then the muted recency/meta line.
|
||||||
expect(
|
expect(
|
||||||
tester.getCenter(find.text(meta)).dy,
|
tester.getCenter(find.text(meta)).dy,
|
||||||
greaterThan(tester.getCenter(find.text(title)).dy),
|
greaterThan(tester.getCenter(find.text(title)).dy),
|
||||||
|
|||||||
Reference in New Issue
Block a user