Files
pipelines/app/lib/features/chat/ui/transcript/chat_turn_chip.dart
T
alan a3a59adb30 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>
2026-11-25 11:10:51 +00:00

167 lines
5.0 KiB
Dart

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.
///
/// 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,
required this.leading,
required this.label,
required this.color,
required this.semanticsLabel,
this.sheet,
this.open,
this.ellipsizeLabel = false,
this.labelSpans,
this.detail,
}) : assert(sheet != null || open != null);
final Key chipKey;
final Widget leading;
final String label;
final Color color;
final String semanticsLabel;
/// The detail content the chip opens, unless [open] presents it instead.
final Widget? sheet;
/// A custom presentation (a full-screen route on a narrow window).
final Future<void> Function(BuildContext context)? open;
/// Shrink a long label to one ellipsized line. Only for a chip whose parent
/// bounds its width (a turn footer's Wrap, an aligned row).
final bool ellipsizeLabel;
/// Styled pieces of [label] (e.g. coloured counts); [label] stays the
/// 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 labelRow = Row(
mainAxisSize: MainAxisSize.min,
children: [
if (widget.ellipsizeLabel || widget.detail != null)
Flexible(child: _label(maxLines: 1, overflow: TextOverflow.ellipsis))
else
_label(),
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: _show,
label: widget.semanticsLabel,
excludeSemantics: true,
child: Padding(
padding: const EdgeInsets.only(top: 2),
child: InkWell(
key: widget.chipKey,
borderRadius: BorderRadius.circular(8),
onTap: _show,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: chatAgentContentInset,
vertical: 6,
),
child: content,
),
),
),
);
}
Widget _label({int? maxLines, TextOverflow? overflow}) {
final style = chatTurnChipTextStyle(context, widget.color);
final spans = widget.labelSpans;
if (spans == null) {
return Text(
widget.label,
maxLines: maxLines,
overflow: overflow,
style: style,
);
}
return Builder(
builder: (context) => Text.rich(
TextSpan(children: spans(context)),
maxLines: maxLines,
overflow: overflow,
style: style,
),
);
}
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) {
return showAppDetails<void>(context, builder: (_) => sheet);
}