Files
pipelines/app/lib/features/chat/conversation/composer_running_border.dart
T
alan 7f31e16bc1 Keep only travelling composer border highlight
Remove glow, full-border tint, and reduced-motion overlay so the running composer paints only a short constant-speed arc. Expand focused arc tests and document verification limits.
2026-11-12 12:43:42 +00:00

129 lines
3.7 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'composer_running_arc.dart';
/// The composer's "agent is working" edge: one short highlight in [primary]
/// and [tertiary] that travels around the pill's rounded border at constant
/// speed. Nothing else changes: the rest of the border, its fill and its
/// thickness stay the normal static outline drawn beneath it.
///
/// Mount it only while a turn runs; disposing it stops the animation, so the
/// border ends cleanly with the turn.
///
/// With reduced motion (the platform's disable-animations setting) it paints
/// nothing, leaving the normal static border, and never ticks.
class ComposerRunningBorder extends StatefulWidget {
const ComposerRunningBorder({
super.key,
required this.shape,
required this.primary,
required this.tertiary,
});
/// The pill's shape, so the highlight follows its edge.
final OutlinedBorder shape;
final Color primary;
final Color tertiary;
/// One lap of the highlight around the border (about 2.5–3 s).
static const Duration period = Duration(milliseconds: 2750);
/// The stroke width of the highlight, drawn just inside the pill's edge.
static const double strokeWidth = 2;
@override
State<ComposerRunningBorder> createState() => _ComposerRunningBorderState();
}
class _ComposerRunningBorderState extends State<ComposerRunningBorder>
with SingleTickerProviderStateMixin {
late final AnimationController _lap = AnimationController(
vsync: this,
duration: ComposerRunningBorder.period,
);
bool _reduced = false;
@override
void initState() {
super.initState();
_lap.repeat();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
final reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
if (reduced == _reduced) return;
_reduced = reduced;
if (reduced) {
_lap.stop();
} else {
_lap.repeat();
}
}
@override
void dispose() {
_lap.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => RepaintBoundary(
key: const Key('chat-composer-running-border'),
child: CustomPaint(
painter: _RunningBorderPainter(
shape: widget.shape,
primary: widget.primary,
tertiary: widget.tertiary,
lap: _reduced ? null : _lap,
),
),
);
}
class _RunningBorderPainter extends CustomPainter {
_RunningBorderPainter({
required this.shape,
required this.primary,
required this.tertiary,
required this.lap,
}) : super(repaint: lap);
final OutlinedBorder shape;
final Color primary;
final Color tertiary;
/// The lap's progress, or null for the static reduced-motion border.
final Animation<double>? lap;
@override
void paint(Canvas canvas, Size size) {
final progress = lap?.value;
// Reduced motion: no highlight; the normal static border shows alone.
if (progress == null || size.isEmpty) return;
const width = ComposerRunningBorder.strokeWidth;
final outline = shape.getOuterPath((Offset.zero & size).deflate(width / 2));
final line = Paint()
..style = PaintingStyle.stroke
..strokeWidth = width;
// The highlight is laid along the outline by arc length, so its speed is
// even around corners and straight edges alike. Only its pieces are drawn.
for (final stroke in runningHighlightStrokes(
outline: outline,
progress: progress,
primary: primary,
tertiary: tertiary,
)) {
canvas.drawPath(stroke.path, line..color = stroke.color);
}
}
@override
bool shouldRepaint(_RunningBorderPainter oldDelegate) =>
oldDelegate.shape != shape ||
oldDelegate.primary != primary ||
oldDelegate.tertiary != tertiary ||
oldDelegate.lap != lap;
}