Files
pipelines/app/lib/features/chat/ui/sessions/session_row_content.dart
T
alan 4c4dcbbd14 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.
2026-10-30 21:05:24 +00:00

242 lines
7.5 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import 'chat_adaptive.dart';
import 'session_harness_icon.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.
/// 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.session,
this.running = false,
this.selected = false,
});
final JsonMap session;
final bool running;
final bool selected;
@override
Widget build(BuildContext context) {
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: [
avatar,
PositionedDirectional(
end: -2,
bottom: -2,
child: Semantics(
key: const Key('chat-row-working'),
label: 'Chat is working',
child: _WorkingBadge(cupertino: cupertino),
),
),
],
);
}
}
class _WorkingBadge extends StatelessWidget {
const _WorkingBadge({required this.cupertino});
final bool cupertino;
@override
Widget build(BuildContext context) {
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),
),
),
);
}
}
/// 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),
),
),
),
],
);
}
}