feat(app): add native content-sized graph stage node

One content-sized stage node as an ordinary native control. Material uses
stock Card.outlined/Card.filled inside an InkWell; Cupertino uses
CupertinoButton.tinted/filled. onSelected reports the definition key
verbatim, one merged button semantics node carries the exact label and
selected state, recorded status is shown only when the caller supplies it,
and invisible U+200B break opportunities reproduce the web's anywhere
wrapping. Painted-boundary and painted-surface tests cover the UI-review
2x outline and Cupertino container defects.
This commit is contained in:
2026-10-21 18:44:18 +01:00
parent f4d4a9869c
commit e63b01154b
6 changed files with 983 additions and 0 deletions
@@ -0,0 +1,126 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/graph_definition.dart';
/// One content-sized stage node as an ordinary native control.
///
/// [node] is the definition identity. [recordedStatus] is executed evidence the
/// caller read from the run; it is shown verbatim and never derived here, so an
/// unvisited or terminal definition node cannot be presented as executed.
class GraphStageNode extends StatelessWidget {
const GraphStageNode({
super.key,
required this.node,
this.recordedStatus,
this.selected = false,
required this.onSelected,
});
final GraphNode node;
/// The run's recorded status word for this node, or null when none exists.
final String? recordedStatus;
/// Whether this definition node is the current graph selection.
final bool selected;
/// Reports [node.key] exactly as the definition recorded it.
final ValueChanged<String> onSelected;
/// Content inset shared by both hosts. It is spacing, not a size: the control
/// still takes its size from its label, and the inset keeps wrapped glyphs
/// clear of a rounded surface's corners.
static const EdgeInsets _contentPadding = EdgeInsets.all(16);
String? get _status {
final status = recordedStatus;
return status != null && status.trim().isNotEmpty ? status : null;
}
String get _label {
final status = _status;
return status == null ? node.label : '${node.label}\n$status';
}
@override
Widget build(BuildContext context) {
final content = ExcludeSemantics(child: _content());
void onPressed() => onSelected(node.key);
return MergeSemantics(
child: Semantics(
button: true,
selected: selected,
label: _label,
child: usesCupertinoHost(context)
? _cupertinoButton(onPressed, content)
: _materialCard(onPressed, content),
),
);
}
/// A stock card, not a stock button: Material's button shape is a stadium,
/// which assumes one line and cuts into a wrapped label's first and last
/// line. A card keeps the rounded-rectangle surface the web node uses, and
/// [selected] only chooses between two stock emphasis levels.
Widget _materialCard(VoidCallback onPressed, Widget content) {
final body = InkWell(
onTap: onPressed,
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: kMinInteractiveDimension),
child: Padding(
padding: _contentPadding,
child: Align(
alignment: AlignmentDirectional.centerStart,
widthFactor: 1,
heightFactor: 1,
child: content,
),
),
),
);
return selected
? Card.filled(
margin: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
child: body,
)
: Card.outlined(
margin: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
child: body,
);
}
/// Tinted is Cupertino's stock low-emphasis surface, so an unselected node is
/// still a visible node body; filled raises the selected one.
Widget _cupertinoButton(VoidCallback onPressed, Widget content) => selected
? CupertinoButton.filled(onPressed: onPressed, child: content)
: CupertinoButton.tinted(onPressed: onPressed, child: content);
Widget _content() {
final status = _status;
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(_breakable(node.label), softWrap: true),
if (status != null) Text(_breakable(status), softWrap: true),
],
);
}
/// The web node uses `overflow-wrap: anywhere`; Flutter text does not break a
/// long unbroken key, so the same invisible break opportunities are added.
/// The visible text and the semantics label stay unchanged.
String _breakable(String value) {
final buffer = StringBuffer();
for (final rune in value.runes) {
buffer
..writeCharCode(rune)
..write('\u200B');
}
return buffer.toString();
}
}