Quieter transcript metadata: day dividers, time-only rows, muted meta rows

- Date once per calendar day: a muted centred divider above each day's
  first timed row (chatDayDividers); rows show only their time ("10:16"),
  with the full date and time kept in the tooltip and semantics. The user's
  time shares the delivery line; a harness notice's time trails its line.
- Activity line and turn chips are secondary: bodyMedium, regular weight,
  onSurfaceVariant (error colour kept for failures), a small chevron_right
  that turns down while its details are open (replaces expand_less).
- Copy / Read aloud: 18 px muted icons; on pointer devices shown only while
  the reply is hovered or an action is focused (also without the gutter);
  touch keeps them visible with a full tap target. The time leads the
  footer so hidden actions leave no gap.
- Settled questions: the question on one line, the operator's answer in
  full on its own line beneath it.
- Meta rows (activity, chips, notices, compaction line) start at the reply
  text's leading edge; turn chips sit in their own column under the answer.
- Scroll fixture: ?timestamps=1 spreads messages over two days.

Row keys are unchanged; the divider joins a row without replacing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 11:10:51 +00:00
parent 33874005c4
commit a3a59adb30
23 changed files with 993 additions and 180 deletions
@@ -78,9 +78,10 @@ List<JsonMap> chatRowQuestions(JsonMap row) {
];
}
/// The collapsed line for one settled question: the question and its outcome,
/// `Which database? · Postgres`, `… · +1 more` when several were answered.
String chatQuestionSummary(JsonMap form) {
/// One settled question's two lines: the question, and its outcome (the
/// operator's answer, `Postgres · +1 more` when several were answered, or
/// `Expired`, `Closed`, `Answered`).
({String question, String outcome}) chatQuestionSummaryParts(JsonMap form) {
final fields = chatFormFields(form);
final answers = form['answers'] is Map
? Map<String, dynamic>.from(form['answers'] as Map)
@@ -93,25 +94,38 @@ String chatQuestionSummary(JsonMap form) {
'${fields.first['key'] ?? ''}'.trim(),
);
}
if (form['cancelled'] == true) return '$question · Expired';
if (form['cancelled'] == true) {
return (question: question, outcome: 'Expired');
}
final answered = [
for (final field in fields)
if (answers.containsKey('${field['key'] ?? ''}'.trim())) field,
];
if (answered.isEmpty) {
return answers.isEmpty ? '$question · Closed' : '$question · Answered';
final outcome = answers.isEmpty ? 'Closed' : 'Answered';
return (question: question, outcome: outcome);
}
final first = answered.first;
final key = '${first['key'] ?? ''}'.trim();
final more = answers.length - 1;
return [
chatQuestionFieldLabel(first, key),
chatQuestionAnswerText(first, answers[key]),
if (more > 0) '+$more more',
].join(' · ');
return (
question: chatQuestionFieldLabel(first, key),
outcome: [
chatQuestionAnswerText(first, answers[key]),
if (more > 0) '+$more more',
].join(' · '),
);
}
/// One settled question as the quiet chip a turn's tools use. It opens a
/// One settled question on one line, `Which database? · Postgres`: the
/// chip's accessible name.
String chatQuestionSummary(JsonMap form) {
final parts = chatQuestionSummaryParts(form);
return '${parts.question} · ${parts.outcome}';
}
/// One settled question as the quiet chip a turn's tools use: the question
/// on one line and the operator's answer in full beneath it. It opens a
/// native sheet with the full question and the recorded answers.
class ChatQuestionChip extends StatelessWidget {
const ChatQuestionChip({super.key, required this.form});
@@ -120,16 +134,25 @@ class ChatQuestionChip extends StatelessWidget {
@override
Widget build(BuildContext context) {
final color = Theme.of(context).colorScheme.onSurfaceVariant;
final theme = Theme.of(context);
final color = theme.colorScheme.onSurfaceVariant;
final parts = chatQuestionSummaryParts(form);
final label = chatQuestionSummary(form);
return ChatTurnChip(
chipKey: ValueKey<String>('chat-question-chip-${form['id']}'),
leading: Icon(Icons.help_outline, size: 14, color: color),
label: label,
label: parts.question,
color: color,
ellipsizeLabel: true,
semanticsLabel: 'Question: $label, expand for details',
sheet: _QuestionSheet(form: form),
detail: Text(
parts.outcome,
key: ValueKey<String>('chat-question-answer-${form['id']}'),
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface,
),
),
);
}
}
@@ -28,6 +28,9 @@ import '../ui/sessions/chat_adaptive.dart';
import '../ui/transcript/chat_markdown_view.dart';
import '../ui/transcript/chat_message_bubble.dart';
import '../ui/transcript/chat_message_view.dart';
import '../ui/transcript/chat_message_timestamp.dart';
import '../ui/transcript/chat_turn_activity_view.dart';
import '../domain/chat_transcript_days.dart';
import '../ui/transcript/chat_transcript_selection.dart';
import '../ui/transcript/chat_injected_rows.dart';
import '../ui/transcript/shown/chat_shown_card.dart';
@@ -1271,6 +1274,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
// other row keeps to the column by insetting past it.
final gutter = chatCopyGutter(constraints.maxWidth);
final media = MediaQuery.paddingOf(context);
// The date shows once per calendar day, above that day's
// first row; each row itself shows only its time.
final days = chatDayDividers(rows);
final transcript = [
for (var index = 0; index < rows.length; index++)
Padding(
@@ -1286,25 +1292,33 @@ class _ChatThreadViewState extends State<ChatThreadView> {
// Slivers mount only visible rows. Defer constructing
// their chips and checking cached widgets until then,
// rather than visiting the entire history per delta.
child: ChatTranscriptRowSelection(
child: ChatCopyGutter(
width: rows[index]['kind'] == 'assistant'
? gutter
: 0,
child: Builder(
builder: (_) => _entering(
rows[index],
_transcriptRow(
child: ChatDayDivided(
day: days[index],
// An answer row starts at the gutter; the divider
// keeps to the reading column.
inset: rows[index]['kind'] == 'assistant'
? gutter
: 0,
child: ChatTranscriptRowSelection(
child: ChatCopyGutter(
width: rows[index]['kind'] == 'assistant'
? gutter
: 0,
child: Builder(
builder: (_) => _entering(
rows[index],
keys[index],
onDismissCompaction:
compactionNotice != null &&
chatNoticeActivityCondition(
rows[index],
) ==
compactionNotice.condition
? () => _dismiss(compactionNotice)
: null,
_transcriptRow(
rows[index],
keys[index],
onDismissCompaction:
compactionNotice != null &&
chatNoticeActivityCondition(
rows[index],
) ==
compactionNotice.condition
? () => _dismiss(compactionNotice)
: null,
),
),
),
),
@@ -2249,8 +2263,13 @@ class _ChatActivityLineState extends State<_ChatActivityLine> {
? Icons.check_circle_outline
: Icons.circle_outlined;
final label = '${widget.row['label'] ?? ''}'.trim();
// The icon starts at the reply text's edge, like the turn's activity line.
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
padding: const EdgeInsetsDirectional.only(
start: chatAgentContentInset,
top: 6,
bottom: 6,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -0,0 +1,52 @@
import '../../../core/api_gateway.dart';
import 'chat_transcript.dart';
/// When a transcript row was recorded, in epoch milliseconds, or null when it
/// carries no valid time (cards, grouped chips, local rows).
///
/// An agent turn records its first message's time on the row; a user turn, a
/// notice or a report carries it on its `message`; a run of grouped notices
/// takes its first notice's.
int? chatRowCreatedAt(JsonMap row) {
final own = chatMessageCreatedAt(row);
if (own != null) return own;
final message = row['message'];
if (message is Map) {
return chatMessageCreatedAt(Map<String, dynamic>.from(message));
}
final messages = row['messages'];
if (messages is List) {
for (final message in messages) {
if (message is! Map) continue;
final time = chatMessageCreatedAt(Map<String, dynamic>.from(message));
if (time != null) return time;
}
}
return null;
}
/// The local calendar day of epoch milliseconds [createdAt].
DateTime chatLocalDay(int createdAt) {
final local = DateTime.fromMillisecondsSinceEpoch(
createdAt,
isUtc: true,
).toLocal();
return DateTime(local.year, local.month, local.day);
}
/// For each of [rows], the local day a date divider above it names, or null.
///
/// The first timed row of each calendar day gets its day, so a transcript
/// shows the date once per day and each row only its time. Rows without a
/// time never start a day and never break one.
List<DateTime?> chatDayDividers(List<JsonMap> rows) {
DateTime? current;
return [
for (final row in rows)
switch (chatRowCreatedAt(row)) {
null => null,
final time when chatLocalDay(time) == current => null,
final time => current = chatLocalDay(time),
},
];
}
@@ -3,6 +3,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'chat_hover_actions.dart';
/// The accessible name of a reply's copy control, and its name just after a
/// copy succeeded.
const String chatCopyLabel = 'Copy';
@@ -67,6 +69,7 @@ class _ChatCopyButtonState extends State<ChatCopyButton> {
}
return IconButton(
key: const Key('chat-message-copy'),
style: chatMessageActionStyle(context),
tooltip: label,
onPressed: _copy,
icon: Icon(_copied ? Icons.check : Icons.copy_outlined),
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import '../../../../ui/adaptive/platform.dart';
import 'chat_hover_actions.dart';
/// The width of the strip left of the reading column that an answer row
/// draws its Copy button in (`chatCopyGutter`); 0 when there is no room, and
@@ -45,7 +45,7 @@ List<Widget> chatCopyGutterInset(
/// pointer is over the answer or the button has focus; it stays in the
/// focus order and the semantics tree when hidden. Touch platforms always
/// show it.
class ChatCopyGutterRow extends StatefulWidget {
class ChatCopyGutterRow extends StatelessWidget {
const ChatCopyGutterRow({
super.key,
required this.width,
@@ -63,54 +63,31 @@ class ChatCopyGutterRow extends StatefulWidget {
/// Keeps the buttons shown without hover (while the reply reads aloud).
final bool pinned;
@override
State<ChatCopyGutterRow> createState() => _ChatCopyGutterRowState();
}
class _ChatCopyGutterRowState extends State<ChatCopyGutterRow> {
bool _hovered = false;
bool _focused = false;
@override
Widget build(BuildContext context) {
final hover = prefersCompactHitTargets(context);
final copy = widget.copy;
final row = Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SizedBox(
key: const Key('chat-copy-gutter'),
width: widget.width,
child: copy == null
? null
: Align(
alignment: Alignment.bottomRight,
child: Focus(
canRequestFocus: false,
skipTraversal: true,
onFocusChange: (focused) =>
setState(() => _focused = focused),
child: AnimatedOpacity(
key: const Key('chat-copy-gutter-visibility'),
opacity: !hover || widget.pinned || _hovered || _focused
? 1
: 0,
duration: const Duration(milliseconds: 120),
alwaysIncludeSemantics: true,
final copy = this.copy;
return ChatHoverRegion(
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SizedBox(
key: const Key('chat-copy-gutter'),
width: width,
child: copy == null
? null
: Align(
alignment: Alignment.bottomRight,
child: ChatHoverReveal(
visibilityKey: const Key('chat-copy-gutter-visibility'),
pinned: pinned,
child: copy,
),
),
),
),
Flexible(child: widget.child),
],
);
if (!hover || copy == null) return row;
return MouseRegion(
onEnter: (_) => setState(() => _hovered = true),
onExit: (_) => setState(() => _hovered = false),
child: row,
),
Flexible(child: child),
],
),
);
}
}
@@ -0,0 +1,105 @@
import 'package:flutter/material.dart';
import '../../../../ui/adaptive/platform.dart';
/// The area whose hover reveals a message's actions ([ChatHoverReveal]). On a
/// touch device it is the bare [child]: there is no hover and the actions
/// always show.
class ChatHoverRegion extends StatefulWidget {
const ChatHoverRegion({super.key, required this.child});
final Widget child;
@override
State<ChatHoverRegion> createState() => _ChatHoverRegionState();
}
class _ChatHoverRegionState extends State<ChatHoverRegion> {
bool _hovered = false;
@override
Widget build(BuildContext context) {
if (!prefersCompactHitTargets(context)) return widget.child;
return MouseRegion(
onEnter: (_) => setState(() => _hovered = true),
onExit: (_) => setState(() => _hovered = false),
child: _ChatHoverScope(hovered: _hovered, child: widget.child),
);
}
}
class _ChatHoverScope extends InheritedWidget {
const _ChatHoverScope({required this.hovered, required super.child});
final bool hovered;
@override
bool updateShouldNotify(_ChatHoverScope oldWidget) =>
hovered != oldWidget.hovered;
}
/// A message's action buttons, shown on a pointer device only while the
/// enclosing [ChatHoverRegion] is hovered, one of them has focus, or [pinned]
/// (a reply reading aloud). Hidden actions stay in the focus order and the
/// semantics tree, so keyboard and assistive users still reach them. Touch
/// devices always show them.
class ChatHoverReveal extends StatefulWidget {
const ChatHoverReveal({
super.key,
required this.child,
this.pinned = false,
this.visibilityKey,
});
final Widget child;
final bool pinned;
/// The key of the fading widget, for tests.
final Key? visibilityKey;
@override
State<ChatHoverReveal> createState() => _ChatHoverRevealState();
}
class _ChatHoverRevealState extends State<ChatHoverReveal> {
bool _focused = false;
@override
Widget build(BuildContext context) {
final hoverDevice = prefersCompactHitTargets(context);
final hovered =
context
.dependOnInheritedWidgetOfExactType<_ChatHoverScope>()
?.hovered ??
false;
final shown = !hoverDevice || widget.pinned || hovered || _focused;
return Focus(
canRequestFocus: false,
skipTraversal: true,
onFocusChange: (focused) => setState(() => _focused = focused),
child: AnimatedOpacity(
key: widget.visibilityKey,
opacity: shown ? 1 : 0,
duration: const Duration(milliseconds: 120),
alwaysIncludeSemantics: true,
child: widget.child,
),
);
}
}
/// The compact, muted style of a message's icon actions (Copy, Read aloud):
/// smaller than the text they follow. Touch devices keep a full-size tap
/// target around the small icon.
ButtonStyle chatMessageActionStyle(BuildContext context) {
final compact = prefersCompactHitTargets(context);
return IconButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,
iconSize: 18,
padding: const EdgeInsets.all(8),
minimumSize: const Size.square(34),
tapTargetSize: compact
? MaterialTapTargetSize.shrinkWrap
: MaterialTapTargetSize.padded,
);
}
@@ -1,8 +1,11 @@
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_transcript_days.dart';
import 'chat_message_bubble.dart';
import 'chat_message_timestamp.dart';
import 'chat_message_view.dart';
import 'chat_turn_activity_view.dart';
/// Content the harness delivered into the session, drawn on the agent's side:
/// an `agent_report` row (a delegated agent's report) and a `system_notice`
@@ -162,28 +165,50 @@ class ChatSystemNoticeLine extends StatelessWidget {
if (text.isEmpty) return const SizedBox.shrink();
final color = Theme.of(context).colorScheme.onSurfaceVariant;
final style = Theme.of(context).textTheme.bodySmall?.copyWith(color: color);
return Semantics(
container: true,
label: 'System notice',
value: text,
child: ExcludeSemantics(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: Icon(
Icons.info_outline,
size: style?.fontSize == null ? 16 : style!.fontSize! * 1.2,
color: color,
final time = chatRowCreatedAt(row);
// The icon starts at the reply text's edge, like the turn's activity line.
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
chatAgentContentInset,
6,
chatAgentContentInset,
6,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Semantics(
container: true,
label: 'System notice',
value: text,
child: ExcludeSemantics(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: Icon(
Icons.info_outline,
size: style?.fontSize == null
? 16
: style!.fontSize! * 1.2,
color: color,
),
),
Expanded(child: Text(text, style: style)),
],
),
),
Expanded(child: Text(text, style: style)),
],
),
),
),
// Its time trails on the same line, as an answer's does.
if (time != null)
Padding(
padding: const EdgeInsetsDirectional.only(start: 8),
child: ChatMessageTimestamp(createdAt: time),
),
],
),
);
}
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
/// The small, non-selectable metadata line for a recorded chat message time.
/// The visible value includes a local date so messages from different days are
/// not ambiguous; the tooltip and semantics expose the full localized value.
/// The local date as the transcript's day divider names it: `25 November 2026`.
String chatDayLabel(BuildContext context, DateTime day) =>
'${day.day} ${MaterialLocalizations.of(context).formatMonthYear(day)}';
/// The small, non-selectable time of a recorded chat message: `10:16`. The
/// date is named once per day by [ChatDayDivider]; the tooltip and semantics
/// still carry the full localized date and time.
class ChatMessageTimestamp extends StatelessWidget {
const ChatMessageTimestamp({super.key, required this.createdAt});
@@ -23,23 +27,92 @@ class ChatMessageTimestamp extends StatelessWidget {
TimeOfDay.fromDateTime(instant),
alwaysUse24HourFormat: true,
);
final date = '${instant.day} ${material.formatMonthYear(instant)}';
final full = '$date, $time';
final style = (Theme.of(context).textTheme.bodySmall ?? const TextStyle())
.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 12,
);
final label = 'Sent $full';
final text = Text('$date · $time', style: style);
final full = '${chatDayLabel(context, instant)}, $time';
final style = chatMetaTextStyle(context);
return SelectionContainer.disabled(
child: Tooltip(
message: full,
child: Semantics(
container: true,
label: label,
label: 'Sent $full',
excludeSemantics: true,
child: text,
child: Text(time, style: style),
),
),
);
}
}
/// The muted small text of transcript metadata (times, the answering model).
TextStyle? chatMetaTextStyle(BuildContext context) => Theme.of(context)
.textTheme
.bodySmall
?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant);
/// A transcript row with the [ChatDayDivider] for [day] above it when the row
/// starts a calendar day. The row keeps its element whether or not a divider
/// joins or leaves above it (an older page arriving moves the day's start).
class ChatDayDivided extends StatelessWidget {
const ChatDayDivided({
super.key,
required this.day,
required this.child,
this.inset = 0,
});
final DateTime? day;
/// Leading space before the divider, so it keeps to the reading column.
final double inset;
final Widget child;
@override
Widget build(BuildContext context) {
final day = this.day;
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (day != null)
Padding(
key: const ValueKey<String>('chat-day-divider'),
padding: EdgeInsetsDirectional.only(start: inset),
child: ChatDayDivider(day: day),
),
KeyedSubtree(key: const ValueKey<String>('chat-day-row'), child: child),
],
);
}
}
/// A quiet centred date between two thin rules, above the first message of
/// each calendar day in the transcript.
class ChatDayDivider extends StatelessWidget {
const ChatDayDivider({super.key, required this.day});
final DateTime day;
@override
Widget build(BuildContext context) {
final label = chatDayLabel(context, day);
return SelectionContainer.disabled(
child: Semantics(
container: true,
header: true,
label: label,
excludeSemantics: true,
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 4),
child: Row(
children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(label, style: chatMetaTextStyle(context)),
),
const Expanded(child: Divider()),
],
),
),
),
);
@@ -9,6 +9,7 @@ import '../../domain/chat_tool_calls.dart';
import '../../domain/chat_transcript.dart';
import 'chat_copy_button.dart';
import 'chat_copy_gutter.dart';
import 'chat_hover_actions.dart';
import 'chat_link_text.dart';
import 'chat_message_bubble.dart';
import 'chat_turn_activity_view.dart';
@@ -55,7 +56,7 @@ class ChatMessageView extends StatelessWidget {
final role = user ? 'User' : 'Assistant';
final content = user ? _userParts(context) : _agentParts(context);
// A wide window draws an answer's Copy in the gutter left of the reading
// column; without room it stays at the start of the answer's footer.
// column; without room it trails the time in the answer's footer.
final gutter = user ? 0.0 : ChatCopyGutter.of(context);
// No visible role label: side and surface say who spoke and the row's
// semantics label names the role. The operator's turn is a neutral bubble
@@ -139,17 +140,17 @@ class ChatMessageView extends StatelessWidget {
const SizedBox(height: 6),
if (content.isNotEmpty || thumbnails.isEmpty)
ChatUserBubble(child: body),
if (footer.isNotEmpty) ...[
// The delivery line and the time share one line under the bubble.
if (footer.isNotEmpty || hasTimestamp) ...[
const SizedBox(height: 2),
Wrap(
key: const Key('chat-message-footer'),
spacing: 8,
alignment: WrapAlignment.end,
crossAxisAlignment: WrapCrossAlignment.center,
children: footer,
children: [...footer, if (hasTimestamp) timestamp],
),
],
if (hasTimestamp) ...[const SizedBox(height: 2), timestamp],
],
);
}
@@ -179,7 +180,7 @@ class ChatMessageView extends StatelessWidget {
}
/// The answer, with its Copy button in the [gutter] to its left when there
/// is one, or else first in its footer.
/// is one, or else after the time in its footer.
Widget _agentRow(
BuildContext context,
List<Widget> content,
@@ -207,7 +208,23 @@ class ChatMessageView extends StatelessWidget {
],
);
if (gutter <= 0) {
return _agentTurn(context, content, answer, actions(Axis.horizontal));
// Without a gutter the actions trail the footer line; a pointer device
// shows them while the answer is hovered or one has focus.
final row = actions(Axis.horizontal);
final reveal = row == null
? null
: ListenableBuilder(
listenable: speechController,
child: row,
builder: (context, child) => ChatHoverReveal(
visibilityKey: const Key('chat-message-actions-visibility'),
pinned: speechController.messageId == id,
child: child!,
),
);
return ChatHoverRegion(
child: _agentTurn(context, content, answer, reveal),
);
}
// The gutter is one button wide: Read aloud stacks above Copy, and stays
// shown on a desktop while this reply reads.
@@ -244,14 +261,14 @@ class ChatMessageView extends StatelessWidget {
if (isChatToolPart(part)) part,
];
final model = '${row['model'] ?? ''}'.trim();
final footer = <Widget>[
?copy,
...this.footer,
// The metadata line: the model that answered and the time, muted; the
// actions (when not in the gutter) trail it.
final meta = <Widget>[
if (model.isNotEmpty)
Text(
model,
key: const Key('chat-reply-model'),
style: TextStyle(fontSize: 12, color: _secondaryColor(context)),
style: chatMetaTextStyle(context),
),
if (chatMessageCreatedAt(row) case final time?)
ChatMessageTimestamp(createdAt: time),
@@ -276,24 +293,37 @@ class ChatMessageView extends StatelessWidget {
),
// A little air between the one-line turn status and the answer.
if (content.isNotEmpty) const SizedBox(height: 6),
if (content.isNotEmpty || footer.isNotEmpty)
if (content.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: chatAgentContentInset,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (content.isNotEmpty) answer,
if (footer.isNotEmpty)
Wrap(
key: const Key('chat-message-footer'),
spacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: footer,
),
],
child: answer,
),
// Settled permissions, questions and changes: meta rows that, like
// the activity line, sit at the row edge with their content inset to
// the answer's text.
if (footer.isNotEmpty)
Column(
key: const Key('chat-turn-chips'),
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: footer,
),
if (copy != null || meta.isNotEmpty)
Padding(
// The time starts at the answer's text edge and the actions
// trail it, so hidden actions leave no gap before it. Without
// metadata the buttons' own inset aligns their icons instead.
padding: EdgeInsetsDirectional.only(
start: meta.isEmpty ? 0 : chatAgentContentInset,
end: chatAgentContentInset,
),
child: Wrap(
key: const Key('chat-message-footer'),
spacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: [...meta, ?copy],
),
),
],
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import '../../speech/speech.dart';
import 'chat_hover_actions.dart';
const chatReadAloudLabel = 'Read aloud';
const chatPauseReadingLabel = 'Pause reading';
@@ -33,9 +34,11 @@ class ChatReadAloudButton extends StatelessWidget {
return ListenableBuilder(
listenable: speech,
builder: (context, _) {
final style = chatMessageActionStyle(context);
if (speech.messageId != messageId) {
return IconButton(
key: const Key('chat-message-read-aloud'),
style: style,
tooltip: chatReadAloudLabel,
onPressed: () => unawaited(speech.read(messageId, parts)),
icon: const Icon(Icons.volume_up_outlined),
@@ -48,6 +51,7 @@ class ChatReadAloudButton extends StatelessWidget {
children: [
IconButton(
key: const Key('chat-message-read-aloud-pause'),
style: style,
tooltip: paused ? chatResumeReadingLabel : chatPauseReadingLabel,
onPressed: () =>
unawaited(paused ? speech.resume() : speech.pause()),
@@ -57,6 +61,7 @@ class ChatReadAloudButton extends StatelessWidget {
),
IconButton(
key: const Key('chat-message-read-aloud-stop'),
style: style,
tooltip: chatStopReadingLabel,
onPressed: () => unawaited(speech.stop()),
icon: const Icon(Icons.stop_outlined),
@@ -7,6 +7,7 @@ import '../../domain/chat_turn_activity.dart';
import '../../../../ui/adaptive/platform.dart';
import 'chat_response_pending.dart';
import 'chat_turn_activity_details.dart';
import 'chat_turn_chip.dart';
/// The activity control's content inset is shared with the rest of the reply.
const chatAgentContentInset = 8.0;
@@ -82,10 +83,10 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
}
final route = DialogRoute<void>(context: context, builder: dialog);
_modal = route;
setState(() => _modal = route);
Navigator.of(context, rootNavigator: true).push(route);
route.completed.then((_) {
if (_modal == route) _modal = null;
if (_modal == route && mounted) setState(() => _modal = null);
});
}
@@ -140,11 +141,15 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: color),
style: chatTurnChipTextStyle(context, color),
),
),
const SizedBox(width: 4),
Icon(Icons.chevron_right, color: color),
const SizedBox(width: 2),
AnimatedRotation(
turns: _modal != null ? 0.25 : 0,
duration: const Duration(milliseconds: 150),
child: Icon(Icons.chevron_right, size: 18, color: color),
),
],
),
);
@@ -1,10 +1,15 @@
import 'package:flutter/material.dart';
import '../../../../ui/adaptive/app_popups.dart';
import 'chat_turn_activity_view.dart';
/// The quiet chip under an agent turn (its tools, its permissions) and the
/// native sheet it opens.
class ChatTurnChip extends StatelessWidget {
///
/// Its leading icon starts at the reply text's edge: the chip sits at the
/// row's edge with the same inset as the turn's activity line. Its chevron is
/// the transcript's expand affordance and turns down while the sheet is open.
class ChatTurnChip extends StatefulWidget {
const ChatTurnChip({
super.key,
required this.chipKey,
@@ -16,6 +21,7 @@ class ChatTurnChip extends StatelessWidget {
this.open,
this.ellipsizeLabel = false,
this.labelSpans,
this.detail,
}) : assert(sheet != null || open != null);
final Key chipKey;
@@ -38,35 +44,72 @@ class ChatTurnChip extends StatelessWidget {
/// plain text. Pieces without their own style inherit the chip's style.
final List<InlineSpan> Function(BuildContext context)? labelSpans;
/// A second line under the label, shown in full (a question's answer).
final Widget? detail;
@override
State<ChatTurnChip> createState() => _ChatTurnChipState();
}
class _ChatTurnChipState extends State<ChatTurnChip> {
bool _open = false;
@override
Widget build(BuildContext context) {
final content = Row(
final labelRow = Row(
mainAxisSize: MainAxisSize.min,
children: [
leading,
const SizedBox(width: 6),
if (ellipsizeLabel)
if (widget.ellipsizeLabel || widget.detail != null)
Flexible(child: _label(maxLines: 1, overflow: TextOverflow.ellipsis))
else
_label(),
Icon(Icons.expand_less, size: 14, color: color),
const SizedBox(width: 2),
AnimatedRotation(
turns: _open ? 0.25 : 0,
duration: const Duration(milliseconds: 150),
child: Icon(Icons.chevron_right, size: 18, color: widget.color),
),
],
);
final content = Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(top: 2),
child: widget.leading,
),
const SizedBox(width: 6),
Flexible(
child: widget.detail == null
? labelRow
: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [labelRow, widget.detail!],
),
),
],
);
return Semantics(
button: true,
expanded: _open,
// The child's own action is excluded with its label, so the node
// carries the activation for assistive technology.
onTap: () => _open(context),
label: semanticsLabel,
onTap: _show,
label: widget.semanticsLabel,
excludeSemantics: true,
child: Padding(
padding: const EdgeInsets.only(top: 2),
child: InkWell(
key: chipKey,
key: widget.chipKey,
borderRadius: BorderRadius.circular(8),
onTap: () => _open(context),
onTap: _show,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 6),
padding: const EdgeInsets.symmetric(
horizontal: chatAgentContentInset,
vertical: 6,
),
child: content,
),
),
@@ -75,10 +118,15 @@ class ChatTurnChip extends StatelessWidget {
}
Widget _label({int? maxLines, TextOverflow? overflow}) {
final style = TextStyle(color: color, fontSize: 13);
final spans = labelSpans;
final style = chatTurnChipTextStyle(context, widget.color);
final spans = widget.labelSpans;
if (spans == null) {
return Text(label, maxLines: maxLines, overflow: overflow, style: style);
return Text(
widget.label,
maxLines: maxLines,
overflow: overflow,
style: style,
);
}
return Builder(
builder: (context) => Text.rich(
@@ -90,12 +138,27 @@ class ChatTurnChip extends StatelessWidget {
);
}
Future<void> _open(BuildContext context) {
if (open case final open?) return open(context);
return showChatTurnSheet(context, sheet!);
Future<void> _show() async {
if (_open) return;
setState(() => _open = true);
try {
if (widget.open case final open?) {
await open(context);
} else {
await showChatTurnSheet(context, widget.sheet!);
}
} finally {
if (mounted) setState(() => _open = false);
}
}
}
/// The secondary text of a turn's meta rows (chips, the activity line):
/// smaller and quieter than the reply's prose.
TextStyle? chatTurnChipTextStyle(BuildContext context, Color color) => Theme.of(
context,
).textTheme.bodyMedium?.copyWith(color: color, fontWeight: FontWeight.w400);
/// The detail surface a turn chip opens: a dialog on desktop and a bottom
/// sheet on a phone.
Future<void> showChatTurnSheet(BuildContext context, Widget sheet) {