diff --git a/app/lib/features/chat/shell/chat_shell_status.dart b/app/lib/features/chat/shell/chat_shell_status.dart index ffbb51cc..d567632f 100644 --- a/app/lib/features/chat/shell/chat_shell_status.dart +++ b/app/lib/features/chat/shell/chat_shell_status.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import '../conversation/chat_card_styles.dart'; import 'chat_shell_command.dart'; import 'chat_shell_run.dart'; +import '../../../ui/status/app_spinner.dart'; /// A command's state at the card's top end: the host's activity indicator /// while it runs, then a status chip (exit code, stopped, interrupted) with @@ -21,7 +22,7 @@ class ChatShellStatus extends StatelessWidget { // As tall as the line of text beside it, at any text scale. child: SizedBox.square( dimension: MediaQuery.textScalerOf(context).scale(20), - child: const CircularProgressIndicator(strokeWidth: 2), + child: const AppSpinner(strokeWidth: 2), ), ); } diff --git a/app/lib/features/chat/ui/sessions/session_activity_badge.dart b/app/lib/features/chat/ui/sessions/session_activity_badge.dart index 2eb4936a..a20bafe9 100644 --- a/app/lib/features/chat/ui/sessions/session_activity_badge.dart +++ b/app/lib/features/chat/ui/sessions/session_activity_badge.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import '../../../../ui/status/app_spinner.dart'; /// The corner badge a chat's avatar wears for its live activity: the /// platform's activity indicator while a turn runs; otherwise, while @@ -53,10 +54,7 @@ class _WorkingBadge extends StatelessWidget { @override Widget build(BuildContext context) { return const _BadgeDisc( - child: SizedBox.square( - dimension: 12, - child: CircularProgressIndicator(strokeWidth: 2), - ), + child: SizedBox.square(dimension: 12, child: AppSpinner(strokeWidth: 2)), ); } } diff --git a/app/lib/features/chat/ui/transcript/chat_reasoning_chip.dart b/app/lib/features/chat/ui/transcript/chat_reasoning_chip.dart index ae7bde29..ada70b02 100644 --- a/app/lib/features/chat/ui/transcript/chat_reasoning_chip.dart +++ b/app/lib/features/chat/ui/transcript/chat_reasoning_chip.dart @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'chat_turn_chip.dart'; +import '../../../../ui/status/app_spinner.dart'; /// `Reasoning` / `Reasoning ยท N steps`. String chatReasoningLabel(int steps) => @@ -80,10 +81,8 @@ class _ChatReasoningChipState extends State { } } -Widget _spinner() => const SizedBox.square( - dimension: 12, - child: CircularProgressIndicator(strokeWidth: 2), -); +Widget _spinner() => + const SizedBox.square(dimension: 12, child: AppSpinner(strokeWidth: 2)); /// The steps an open sheet listens to. The turn can leave the tree while its /// sheet is still open (its row scrolled away or replaced), so the notifier is diff --git a/app/lib/features/chat/ui/transcript/chat_tool_calls_view.dart b/app/lib/features/chat/ui/transcript/chat_tool_calls_view.dart index 2809cccd..b9c22de4 100644 --- a/app/lib/features/chat/ui/transcript/chat_tool_calls_view.dart +++ b/app/lib/features/chat/ui/transcript/chat_tool_calls_view.dart @@ -5,6 +5,7 @@ import '../../../../ui/text/monospace.dart'; import '../../domain/chat_tool_calls.dart'; import 'chat_turn_chip.dart'; import 'native_disclosure.dart'; +import '../../../../ui/status/app_spinner.dart'; /// A turn's one tool summary below its answer, as the web's chip: `N tools`, /// spinning while a call runs and tinted when one failed. It opens a sheet with @@ -25,7 +26,7 @@ class ChatToolCallsChip extends StatelessWidget { final leading = running ? const SizedBox.square( dimension: 12, - child: CircularProgressIndicator(strokeWidth: 2), + child: AppSpinner(strokeWidth: 2), ) : Icon(Icons.build_outlined, size: 14, color: color); return ChatTurnChip( diff --git a/app/lib/ui/navigation/bar_icon_button.dart b/app/lib/ui/navigation/bar_icon_button.dart index d671ae43..a909f692 100644 --- a/app/lib/ui/navigation/bar_icon_button.dart +++ b/app/lib/ui/navigation/bar_icon_button.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import '../../ui/status/app_spinner.dart'; /// One icon action of a segmented bar's actions pill (or any toolbar row). /// @@ -42,7 +43,7 @@ class BarIconButton extends StatelessWidget { child: Center( child: SizedBox.square( dimension: 20, - child: CircularProgressIndicator(strokeWidth: 2), + child: AppSpinner(strokeWidth: 2), ), ), ), diff --git a/app/lib/ui/status/app_spinner.dart b/app/lib/ui/status/app_spinner.dart new file mode 100644 index 00000000..72d48c7f --- /dev/null +++ b/app/lib/ui/status/app_spinner.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; + +/// The standard indeterminate [CircularProgressIndicator], with its own +/// animation controller. +/// +/// Without a `controller`, the Material indicator looks its controller up on +/// every animation frame: an inherited theme, then a walk up the whole widget +/// tree for the ambient `Theme`. In a deep tree (a chat row, a running turn's +/// chips) that walk is the indicator's largest cost; owning the controller +/// skips it. The motion is the stock one: same period, same curves. +class AppSpinner extends StatefulWidget { + const AppSpinner({super.key, this.strokeWidth}); + + final double? strokeWidth; + + /// The stock indeterminate circular period (`progress_indicator.dart`). + static const Duration period = Duration(milliseconds: 1333 * 2222); + + @override + State createState() => _AppSpinnerState(); +} + +class _AppSpinnerState extends State + with SingleTickerProviderStateMixin { + late final AnimationController _controller = AnimationController( + vsync: this, + duration: AppSpinner.period, + )..repeat(); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => CircularProgressIndicator( + controller: _controller, + strokeWidth: widget.strokeWidth, + ); +} diff --git a/app/test/ui/status/app_spinner_test.dart b/app/test/ui/status/app_spinner_test.dart new file mode 100644 index 00000000..374dd2c6 --- /dev/null +++ b/app/test/ui/status/app_spinner_test.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/status/app_spinner.dart'; + +void main() { + testWidgets('the spinner owns its controller, so no per-frame lookup', ( + tester, + ) async { + await tester.pumpWidget( + const MaterialApp(home: Center(child: AppSpinner(strokeWidth: 2))), + ); + final indicator = tester.widget( + find.byType(CircularProgressIndicator), + ); + expect(indicator.controller, isNotNull); + expect(indicator.controller!.isAnimating, isTrue); + expect(indicator.strokeWidth, 2); + await tester.pumpWidget(const SizedBox()); + }); +}