feat(app): pulse the run graph's recorded current stage

Mark the run's recorded current stage on the run graph while it executes. The
halo is a foreground painter outside the node box, so it adds no size, hit
target or semantics, and it is derived only from RunGraphState.activeStage,
which is non-null only while the run reports executing. Reduced motion keeps a
still ring instead of animating.

Widget tests cover the sole active node, a finished run with no halo or ticker,
reduced motion, toggling it at runtime and unchanged node extents.
This commit is contained in:
2026-10-22 17:17:39 +01:00
parent cf6da4acaa
commit 407551b8bb
6 changed files with 379 additions and 21 deletions
@@ -15,6 +15,7 @@ class GraphStageNode extends StatelessWidget {
required this.node,
this.recordedStatus,
this.selected = false,
this.active = false,
required this.onSelected,
});
@@ -26,6 +27,12 @@ class GraphStageNode extends StatelessWidget {
/// Whether this definition node is the current graph selection.
final bool selected;
/// Whether the run records this node as its current stage while executing.
///
/// Set only from the run's recorded active-stage evidence; a finished run has
/// none, so an idle graph never shows live activity.
final bool active;
/// Reports [node.key] exactly as the definition recorded it.
final ValueChanged<String> onSelected;
@@ -48,7 +55,7 @@ class GraphStageNode extends StatelessWidget {
Widget build(BuildContext context) {
final content = ExcludeSemantics(child: _content());
void onPressed() => onSelected(node.key);
return MergeSemantics(
final control = MergeSemantics(
child: Semantics(
button: true,
selected: selected,
@@ -58,6 +65,7 @@ class GraphStageNode extends StatelessWidget {
: _materialCard(onPressed, content),
),
);
return active ? StageActivityHalo(child: control) : control;
}
/// A stock card, not a stock button: Material's button shape is a stadium,
@@ -124,3 +132,113 @@ class GraphStageNode extends StatelessWidget {
return buffer.toString();
}
}
/// The live-stage halo around a native node.
///
/// It paints outside the node's measured box, so it never changes a node extent
/// or the layout, and it takes no pointer input. The ring pulses in the host's
/// primary colour and stays still when the platform asks for reduced motion.
class StageActivityHalo extends StatefulWidget {
const StageActivityHalo({super.key, required this.child});
final Widget child;
/// One full pulse; slow enough to read as activity, not as a progress bar.
static const Duration period = Duration(milliseconds: 1600);
@override
State<StageActivityHalo> createState() => _StageActivityHaloState();
}
class _StageActivityHaloState extends State<StageActivityHalo>
with SingleTickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
vsync: this,
duration: StageActivityHalo.period,
);
bool _reducedMotion = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
final reducedMotion = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
if (reducedMotion == _reducedMotion &&
(_controller.isAnimating || reducedMotion)) {
return;
}
_reducedMotion = reducedMotion;
if (reducedMotion) {
// A still ring still marks the current stage; only the animation stops.
_controller.stop();
} else {
_controller.repeat(reverse: true);
}
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final color = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
return AnimatedBuilder(
animation: _controller,
builder: (context, child) => CustomPaint(
foregroundPainter: StageActivityHaloPainter(
color: color,
progress: _reducedMotion ? 0.5 : _controller.value,
),
child: child,
),
child: widget.child,
);
}
}
/// Paints the halo just outside a node's own box.
///
/// [progress] runs 0..1 so the ring breathes outward and fades; the radius is
/// derived from the node's own size rather than a fixed corner value, because
/// the node keeps its host's stock shape.
class StageActivityHaloPainter extends CustomPainter {
const StageActivityHaloPainter({required this.color, required this.progress});
final Color color;
final double progress;
static const double _baseSpread = 2;
static const double _pulseSpread = 5;
static const double _strokeWidth = 2;
static const double _blurSigma = 4;
@override
void paint(Canvas canvas, Size size) {
if (size.isEmpty) return;
final rect = Offset.zero & size;
final spread = _baseSpread + _pulseSpread * progress;
final radius = Radius.circular(size.shortestSide * 0.25);
final paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = _strokeWidth
..color = color.withValues(alpha: 0.55 - 0.3 * progress)
..maskFilter = const MaskFilter.blur(BlurStyle.normal, _blurSigma);
canvas.drawRRect(
RRect.fromRectAndRadius(rect.inflate(spread), radius),
paint,
);
}
/// Like the node itself, the halo adds no hit target.
@override
bool hitTest(Offset position) => false;
@override
bool shouldRepaint(StageActivityHaloPainter oldDelegate) =>
oldDelegate.color != color || oldDelegate.progress != progress;
}
@@ -199,6 +199,7 @@ class RunGraphCanvas extends StatelessWidget {
}
final executedIds = {for (final route in executed) route.id};
final size = Size(routing.width, routing.height);
final activeStage = state.activeStage;
final cupertino = usesCupertinoHost(context);
final executedColor = cupertino
? CupertinoTheme.of(context).primaryColor
@@ -226,6 +227,7 @@ class RunGraphCanvas extends StatelessWidget {
node: nodesByKey[box.key]!,
recordedStatus: recordedStatuses[box.key],
selected: box.key == selectedStage,
active: box.key == activeStage,
opensVisit:
!nodesByKey[box.key]!.terminal &&
state.isStageVisited(box.key),
@@ -250,7 +252,9 @@ class RunGraphCanvas extends StatelessWidget {
/// One placed run node. A visited stage is the native control with its recorded
/// status; an unvisited node and a terminal are labels with no tap target or
/// button semantics, because neither owns a recorded visit to open.
/// button semantics, because neither owns a recorded visit to open. [active]
/// marks the run's recorded current stage while it executes; it only adds the
/// live halo, never a visit or a control.
class RunGraphNode extends StatelessWidget {
const RunGraphNode({
super.key,
@@ -259,12 +263,14 @@ class RunGraphNode extends StatelessWidget {
required this.opensVisit,
required this.onSelected,
this.selected = false,
this.active = false,
});
final GraphNode node;
final String? recordedStatus;
final bool opensVisit;
final bool selected;
final bool active;
final ValueChanged<String> onSelected;
@override
@@ -275,6 +281,7 @@ class RunGraphNode extends StatelessWidget {
node: node,
recordedStatus: status,
selected: selected,
active: active,
onSelected: onSelected,
);
}
@@ -286,6 +293,7 @@ class RunGraphNode extends StatelessWidget {
child: GraphStageNode(
node: node,
recordedStatus: status,
active: active,
onSelected: (_) {},
),
),