Remove Cupertino chat transcript branches

Keep the existing Material transcript path while preserving public Cupertino parameters for callers. Narrow transcript tests to the Material-only behavior and remove Cupertino-only fixtures.
This commit is contained in:
2026-11-11 11:46:13 +00:00
parent 1c2bb8733a
commit fbe1928f59
52 changed files with 1524 additions and 2947 deletions
@@ -1,13 +1,11 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'chat_transcript_selection.dart';
import 'chat_code_hover.dart';
import '../../../../ui/text/monospace.dart';
import '../sessions/chat_adaptive.dart';
import 'chat_link_launcher.dart';
import 'chat_link_spans.dart';
import 'chat_markdown.dart';
@@ -82,8 +80,6 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
// A new token or usage update elsewhere in the turn must not reparse and
// rebuild every earlier answer part, or disturb its text selection.
if (_rendered != null) return _rendered!;
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final gap = chatParagraphGap(context);
final blocks = chatMarkdownCache.blocksFor(widget.text);
return _rendered = Listener(
@@ -105,7 +101,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
padding: EdgeInsets.only(
top: index == 0 ? 0 : _gapAfter(blocks[index - 1], gap),
),
child: _block(context, blocks[index], cupertino),
child: _block(context, blocks[index]),
),
],
),
@@ -119,28 +115,23 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
double _gapAfter(MarkdownBlock previous, double paragraphGap) =>
previous is MarkdownHeading ? 8 : paragraphGap;
Widget _block(BuildContext context, MarkdownBlock block, bool cupertino) {
Widget _block(BuildContext context, MarkdownBlock block) {
switch (block) {
case MarkdownHeading(level: final level, text: final text):
return Semantics(
container: true,
headingLevel: level,
child: _text(
context,
text,
cupertino: cupertino,
style: _headingStyle(context, level, cupertino),
),
child: _text(context, text, style: _headingStyle(context, level)),
);
case MarkdownParagraph(text: final text):
return _text(context, text, cupertino: cupertino);
return _text(context, text);
case MarkdownRule():
return Divider(color: _dividerColor(context, cupertino));
return Divider(color: _dividerColor(context));
case MarkdownQuote(lines: final lines):
return DecoratedBox(
decoration: BoxDecoration(
border: BorderDirectional(
start: BorderSide(color: _dividerColor(context, cupertino)),
start: BorderSide(color: _dividerColor(context)),
),
),
child: Padding(
@@ -151,8 +142,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
spacing: 4,
children: [
for (final line in lines)
if (line.trim().isNotEmpty)
_text(context, line, cupertino: cupertino),
if (line.trim().isNotEmpty) _text(context, line),
],
),
),
@@ -176,15 +166,9 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
children: [
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: Text(ordered ? '${index + 1}.' : '\u2022'),
),
Expanded(
child: _text(
context,
items[index],
cupertino: cupertino,
),
child: Text(ordered ? '${index + 1}.' : '•'),
),
Expanded(child: _text(context, items[index])),
],
),
),
@@ -196,22 +180,17 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
label: 'table',
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
border: TableBorder.all(color: _dividerColor(context, cupertino)),
border: TableBorder.all(color: _dividerColor(context)),
children: [
TableRow(
decoration: BoxDecoration(
color: _headerFill(context, cupertino),
),
decoration: BoxDecoration(color: _headerFill(context)),
children: [
for (final cell in header)
_cell(context, cell, cupertino, header: true),
for (final cell in header) _cell(context, cell, header: true),
],
),
for (final row in rows)
TableRow(
children: [
for (final cell in row) _cell(context, cell, cupertino),
],
children: [for (final cell in row) _cell(context, cell)],
),
],
),
@@ -219,16 +198,14 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
case MarkdownCode(language: final language, code: final code):
final labelStyle = _roleStyle(
context,
cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.labelSmall,
Theme.of(context).textTheme.labelSmall,
);
return ChatCodeCopyRegion(
code: code,
cupertino: cupertino,
cupertino: false,
label: Text(markdownCodeLabel(language), style: labelStyle),
child: DecoratedBox(
decoration: BoxDecoration(color: _codeFill(context, cupertino)),
decoration: BoxDecoration(color: _codeFill(context)),
child: Padding(
padding: const EdgeInsets.all(12),
child: ChatTranscriptHorizontalScrollView(
@@ -244,80 +221,56 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
}
}
Widget _cell(
BuildContext context,
String text,
bool cupertino, {
bool header = false,
}) {
Widget _cell(BuildContext context, String text, {bool header = false}) {
final style = header
? _roleStyle(
context,
cupertino
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
: Theme.of(context).textTheme.labelLarge,
)
? _roleStyle(context, Theme.of(context).textTheme.labelLarge)
: null;
return Semantics(
role: header ? SemanticsRole.columnHeader : null,
child: Padding(
padding: const EdgeInsets.all(8),
child: _text(context, text, cupertino: cupertino, style: style),
child: _text(context, text, style: style),
),
);
}
Widget _text(
BuildContext context,
String text, {
required bool cupertino,
TextStyle? style,
}) {
Widget _text(BuildContext context, String text, {TextStyle? style}) {
return Builder(
builder: (textContext) => Text.rich(
TextSpan(children: _spans(textContext, parseInline(text), cupertino)),
TextSpan(children: _spans(textContext, parseInline(text))),
style: style,
),
);
}
List<InlineSpan> _spans(
BuildContext context,
List<MarkdownInline> spans,
bool cupertino,
) => [
List<InlineSpan> _spans(BuildContext context, List<MarkdownInline> spans) => [
for (final span in spans)
switch (span) {
MarkdownPlain(text: final text) => TextSpan(text: text),
MarkdownInlineCode(text: final text) => _inlineCode(
context,
text,
cupertino,
),
MarkdownInlineCode(text: final text) => _inlineCode(context, text),
MarkdownStrong(spans: final inner) => TextSpan(
style: const TextStyle(fontWeight: FontWeight.bold),
children: _spans(context, inner, cupertino),
children: _spans(context, inner),
),
MarkdownEmphasis(spans: final inner) => TextSpan(
style: const TextStyle(fontStyle: FontStyle.italic),
children: _spans(context, inner, cupertino),
children: _spans(context, inner),
),
MarkdownLink(url: final url, spans: final inner) => _link(
context,
url,
inner,
cupertino,
),
},
];
TextSpan _inlineCode(BuildContext context, String text, bool cupertino) {
TextSpan _inlineCode(BuildContext context, String text) {
final token = text;
return TextSpan(
text: text,
style: TextStyle(
fontFamily: appMonospaceFamily,
backgroundColor: _codeFill(context, cupertino),
backgroundColor: _codeFill(context),
),
onEnter: (event) {
if (_route?.isCurrent != false) {
@@ -326,7 +279,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
token,
text,
event.position,
cupertino: cupertino,
cupertino: false,
);
}
},
@@ -338,11 +291,10 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
BuildContext context,
String url,
List<MarkdownInline> spans,
bool cupertino,
) => _links.link(
context,
url,
_spans(context, spans, cupertino),
_spans(context, spans),
onOpen: (uri) {
final onOpenLink = widget.onOpenLink;
if (onOpenLink != null) return onOpenLink(uri.toString());
@@ -353,46 +305,32 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
/// Heading roles are a non-increasing sequence from the host's own text
/// theme. H3–H6 share one title role, matching the web renderer's flat
/// lower-heading treatment, and no level falls back to a body role, so a
/// heading never reads like a paragraph. Cupertino has two title roles, so
/// H2–H6 share the middle-title role rather than plain body text.
TextStyle? _headingStyle(BuildContext context, int level, bool cupertino) {
final TextStyle? role;
if (cupertino) {
final theme = CupertinoTheme.of(context).textTheme;
role = switch (level) {
1 => theme.navLargeTitleTextStyle,
_ => theme.navTitleTextStyle,
};
} else {
final text = Theme.of(context).textTheme;
role = switch (level) {
1 => text.headlineSmall,
2 => text.titleLarge,
_ => text.titleMedium,
};
}
/// heading never reads like a paragraph.
TextStyle? _headingStyle(BuildContext context, int level) {
final text = Theme.of(context).textTheme;
final role = switch (level) {
1 => text.headlineSmall,
2 => text.titleLarge,
_ => text.titleMedium,
};
return _roleStyle(context, role);
}
/// Merges a host theme role into the ambient text style. Cupertino roles are
/// `inherit: false`, which `Text` cannot merge directly.
/// Merges a host theme role into the ambient text style.
TextStyle? _roleStyle(BuildContext context, TextStyle? role) => role == null
? null
: DefaultTextStyle.of(
context,
).style.copyWith(inherit: true).merge(role.copyWith(inherit: true));
Color _dividerColor(BuildContext context, bool cupertino) {
if (cupertino) return CupertinoColors.separator.resolveFrom(context);
Color _dividerColor(BuildContext context) {
final theme = Theme.of(context);
return theme.dividerTheme.color ?? theme.dividerColor;
}
Color _codeFill(BuildContext context, bool cupertino) => cupertino
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHighest;
Color _codeFill(BuildContext context) =>
Theme.of(context).colorScheme.surfaceContainerHighest;
Color _headerFill(BuildContext context, bool cupertino) => cupertino
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHigh;
Color _headerFill(BuildContext context) =>
Theme.of(context).colorScheme.surfaceContainerHigh;
}