feat(app): add native chat transcript message row
Render one transcriptRows row with native controls: role-labelled user and agent messages, verbatim user text, client and attachment names (own name, URI basename, else file), ordered agent parts, and collapsed reasoning, tool and unknown-part bodies using ExpansionTile or a Cupertino disclosure. Blank known parts draw nothing so they no longer fall through to the unknown-part disclosure; closed bodies build lazily. Adds focused widget tests, the fixture probe pair and the C2 evidence note.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
|
||||
/// A collapsed block opened with the host's own disclosure control.
|
||||
///
|
||||
/// [childBuilder] runs only while the block is open, so a closed disclosure
|
||||
/// never encodes or lays out its body.
|
||||
class NativeDisclosure extends StatefulWidget {
|
||||
const NativeDisclosure({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.childBuilder,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final WidgetBuilder childBuilder;
|
||||
|
||||
@override
|
||||
State<NativeDisclosure> createState() => _NativeDisclosureState();
|
||||
}
|
||||
|
||||
class _NativeDisclosureState extends State<NativeDisclosure> {
|
||||
bool _expanded = false;
|
||||
|
||||
void _toggle() => setState(() => _expanded = !_expanded);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (chatControlsStyleOf(context) != ChatControlsStyle.cupertino) {
|
||||
return ExpansionTile(
|
||||
title: Text(widget.label),
|
||||
maintainState: false,
|
||||
// A transcript block starts at the row edge, like its answer text; the
|
||||
// tile's own padding would indent it, and its body defaults to centred,
|
||||
// which floats a short body in the middle of the row.
|
||||
tilePadding: EdgeInsets.zero,
|
||||
expandedAlignment: AlignmentDirectional.centerStart,
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [Builder(builder: widget.childBuilder)],
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// One node carries the label, the button action and the state; the
|
||||
// Cupertino button's own node would otherwise drop the state.
|
||||
Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
expanded: _expanded,
|
||||
label: widget.label,
|
||||
onTap: _toggle,
|
||||
child: ExcludeSemantics(
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _toggle,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(widget.label, textAlign: TextAlign.start),
|
||||
),
|
||||
Icon(
|
||||
_expanded
|
||||
? CupertinoIcons.chevron_up
|
||||
: CupertinoIcons.chevron_down,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_expanded) widget.childBuilder(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user