feat(chat): contact-list chat rows with avatar, time and unread emphasis

Rows lead with a circular harness avatar, put the time beside the title,
collapse metadata into one muted model · folder line and trail the
actions menu. Unread chats are bold with an accent time and dot, running
chats badge their avatar, and Star moves into the menu.
This commit is contained in:
2026-10-30 21:05:24 +00:00
parent 44b2cff347
commit 4c4dcbbd14
16 changed files with 519 additions and 555 deletions
@@ -1,182 +1,241 @@
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import 'chat_adaptive.dart';
import 'session_harness_icon.dart';
/// Hierarchical row copy shared by the Material and Cupertino list variants.
/// Metadata stays on the left; recency and native actions share its vertical
/// space on the right instead of adding full-width rows below it.
class ChatSessionRowContent extends StatelessWidget {
const ChatSessionRowContent({
/// 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.
/// 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
/// of a line of its own; a selected chat's avatar takes the accent fill.
class ChatSessionAvatar extends StatelessWidget {
const ChatSessionAvatar({
super.key,
required this.title,
required this.status,
required this.recency,
required this.meta,
required this.titleStyle,
required this.metaStyle,
required this.statusStyle,
this.loading = false,
this.leading,
this.actions = const [],
required this.session,
this.running = false,
this.selected = false,
});
final String title;
final String? status;
final String? recency;
final List<String> meta;
final TextStyle titleStyle;
final TextStyle metaStyle;
final TextStyle statusStyle;
final bool loading;
final Widget? leading;
final List<Widget> actions;
final JsonMap session;
final bool running;
final bool selected;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final Color fill;
final Color mark;
if (cupertino) {
final primary = CupertinoTheme.of(context).primaryColor;
fill = selected
? primary.withValues(alpha: 0.2)
: CupertinoColors.systemGrey5.resolveFrom(context);
mark = selected ? primary : CupertinoColors.label.resolveFrom(context);
} else {
final scheme = Theme.of(context).colorScheme;
fill = selected
? scheme.primaryContainer
: scheme.surfaceContainerHighest;
mark = selected ? scheme.onPrimaryContainer : scheme.onSurfaceVariant;
}
final avatar = CircleAvatar(
backgroundColor: fill,
child: SessionHarnessIcon(session: session, color: mark),
);
if (!running) return avatar;
return Stack(
clipBehavior: Clip.none,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (leading != null) ...[leading!, const SizedBox(width: 8)],
Expanded(
child: Text(
title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: titleStyle,
),
),
],
),
LayoutBuilder(
builder: (context, constraints) {
final hasTrailing =
actions.isNotEmpty || (recency?.isNotEmpty ?? false);
final nativeTarget =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? kMinInteractiveDimensionCupertino
: kMinInteractiveDimension;
final trailingWidth = math.min(
constraints.maxWidth,
math.max(
nativeTarget,
math.min(
constraints.maxWidth * 0.45,
nativeTarget * math.max(1, actions.length),
),
),
);
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
if (status != null)
_StatusLabel(status: status!, style: statusStyle),
if (status == null && loading)
Semantics(
label: 'Chat is working',
child: const _LoadingStatus(),
),
for (final line in meta)
Text(
line,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: metaStyle,
),
],
),
),
if (hasTrailing)
SizedBox(
width: trailingWidth,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
if (recency?.isNotEmpty ?? false)
Text(
recency!,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.end,
style: metaStyle,
),
if (actions.isNotEmpty)
Wrap(alignment: WrapAlignment.end, children: actions),
],
),
),
],
);
},
avatar,
PositionedDirectional(
end: -2,
bottom: -2,
child: Semantics(
key: const Key('chat-row-working'),
label: 'Chat is working',
child: _WorkingBadge(cupertino: cupertino),
),
),
],
);
}
}
class _LoadingStatus extends StatelessWidget {
const _LoadingStatus();
class _WorkingBadge extends StatelessWidget {
const _WorkingBadge({required this.cupertino});
final bool cupertino;
@override
Widget build(BuildContext context) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return const Align(
alignment: AlignmentDirectional.centerStart,
child: CupertinoActivityIndicator(radius: 7),
);
}
return const Align(
alignment: AlignmentDirectional.centerStart,
child: SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
final background = cupertino
? CupertinoColors.systemBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surface;
return DecoratedBox(
decoration: BoxDecoration(color: background, shape: BoxShape.circle),
child: Padding(
padding: const EdgeInsets.all(2),
child: cupertino
? const CupertinoActivityIndicator(radius: 6)
: const SizedBox.square(
dimension: 12,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
);
}
}
class _StatusLabel extends StatelessWidget {
const _StatusLabel({required this.status, required this.style});
/// 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 status;
final TextStyle style;
final String title;
final String recency;
final bool unread;
final bool starred;
@override
Widget build(BuildContext context) {
if (status != 'New') {
return Text(
status,
maxLines: 1,
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(
status,
maxLines: 1,
style: style.copyWith(
color: Colors.white,
fontWeight: FontWeight.w700,
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),
),
),
),
],
);
}
}