Replace background task spinner with count ring

Show the running-task count inside a primary-colour progress ring while preserving the composer button size and reduced-motion behavior. Update the related widget and integration tests and document the new indicator.
This commit is contained in:
2026-11-12 10:51:44 +00:00
parent 82418d31a7
commit 4fba2794eb
6 changed files with 195 additions and 122 deletions
@@ -147,13 +147,11 @@ class _ChatBackgroundTasksState extends State<ChatBackgroundTasks> {
visualDensity: VisualDensity.compact,
),
onPressed: _open,
// The layers turn only while a task runs; automations stay still.
// A ring around the running count while tasks run; automations stay
// on their static schedule icon.
icon: automationOnly
? const Icon(Icons.schedule, size: 16)
: ChatTaskSpinner(
spinning: count > 0,
child: const Icon(Icons.layers_outlined, size: 16),
),
: ChatTaskSpinner(running: count),
label: caption(),
);
return Padding(
@@ -170,7 +168,7 @@ class _ChatBackgroundTasksState extends State<ChatBackgroundTasks> {
: 'Background work, $label; task list unavailable')
: 'Background work, $label',
child: Tooltip(
message: label,
message: count > 0 ? 'Background tasks ($count running)' : label,
excludeFromSemantics: true,
child: button,
),
@@ -1,71 +1,50 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
/// Turns [child] once every [period] while [spinning]; static otherwise. With
/// reduced motion it never turns. Hidden UI is silenced by TickerMode.
class ChatTaskSpinner extends StatefulWidget {
const ChatTaskSpinner({
super.key,
required this.spinning,
required this.child,
});
/// Background-task glyph for the composer. While [running] is above zero it
/// shows a thin Material progress ring around the count; with reduced motion
/// the ring holds one static quarter segment instead of spinning. With no
/// running task it is the plain layers icon, with no ring. Always [size] square
/// so the button keeps the same dimensions in every state.
class ChatTaskSpinner extends StatelessWidget {
const ChatTaskSpinner({super.key, required this.running, this.size = 16});
final bool spinning;
final Widget child;
final int running;
final double size;
/// One full turn while tasks run.
static const Duration period = Duration(milliseconds: 2500);
/// Fraction of the ring drawn while reduced motion holds it still.
static const double reducedSegment = 0.25;
@override
State<ChatTaskSpinner> createState() => _ChatTaskSpinnerState();
}
class _ChatTaskSpinnerState extends State<ChatTaskSpinner>
with SingleTickerProviderStateMixin {
late final AnimationController _turns = AnimationController(
vsync: this,
duration: ChatTaskSpinner.period,
);
bool _reduced = false;
@override
void initState() {
super.initState();
_sync();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
_sync();
}
@override
void didUpdateWidget(covariant ChatTaskSpinner oldWidget) {
super.didUpdateWidget(oldWidget);
_sync();
}
void _sync() {
if (widget.spinning && !_reduced) {
if (!_turns.isAnimating) _turns.repeat();
} else {
_turns
..stop()
..value = 0;
}
}
@override
void dispose() {
_turns.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => RotationTransition(
key: const Key('chat-background-tasks-spinner'),
turns: _turns,
child: widget.child,
);
Widget build(BuildContext context) {
final theme = Theme.of(context);
final reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
final content = running > 0
? Stack(
alignment: Alignment.center,
children: [
SizedBox.square(
dimension: size,
child: CircularProgressIndicator(
strokeWidth: 2,
color: theme.colorScheme.primary,
value: reduced ? reducedSegment : null,
),
),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
'$running',
key: const Key('chat-background-tasks-count'),
style: theme.textTheme.labelSmall,
),
),
],
)
: Icon(Icons.layers_outlined, size: size);
return SizedBox.square(
key: const Key('chat-background-tasks-spinner'),
dimension: size,
child: content,
);
}
}
+41
View File
@@ -0,0 +1,41 @@
# Background tasks ring (composer)
Replaces the rotating layers icon in the composer's background-tasks button.
## Behaviour
- `chat_task_spinner.dart`: `ChatTaskSpinner(running:)`, 16 px square in every state.
- `running > 0`: Material `CircularProgressIndicator` (indeterminate, stroke 2,
primary colour) with the running count centred inside (`FittedBox` scales
the digit down under large text scaling).
- reduced motion (`MediaQuery.disableAnimations`): the same ring holds one
static quarter segment (`value: 0.25`) instead of spinning.
- `running == 0`: static `Icons.layers_outlined`, no ring.
- `chat_background_tasks.dart`: automation-only state keeps its static schedule
icon. Tooltip with running tasks is `Background tasks (N running)`; without
running tasks it keeps the caption label (e.g. `1 automation`, `Tasks`).
Semantics label is unchanged.
- Button size, padding and caption are unchanged.
## Tests (memwatch, from app/)
| Run | Paths | Result |
|---|---|---|
| 1 | `chat_task_spinner_test`, `chat_background_tasks_test`, `chat_background_tasks_modal_test`, `chat_background_task_metadata_test`, `chat_background_tasks_gui_test`, `chat_background_tasks_controller_test`, `chat_automation_lifecycle_test` | FAIL 37/38 (`chat_background_tasks_test` "combined caption..." — my test's `find.descendant` on the count key; fixed) |
| 2 | same seven paths | PASS 38/38, exit 0 |
`tool/analyze.sh`: clean, exit 0.
Test expectation changes (all from the requested behaviour):
- `chat_task_spinner_test.dart` rewritten for the ring: indeterminate value,
stroke 2, primary colour (light and dark), count text, same 16 px size in
every state, reduced-motion static segment, tooltip on the composer button.
- `chat_background_tasks_test.dart`: tooltip `2 tasks, 12 automations` became
`Background tasks (2 running)`; the composer count now also appears inside the
ring, so the caption check expects two `2` texts and the ring's count is checked
by its key.
## Not verified here
- Light/dark captures and rendered checks were not done in this stage; ui-review owns them.
- No device or browser run.
+3 -3
View File
@@ -21,9 +21,9 @@
- **More menu Stop.** `chat_thread_view.dart` adds a `Stop` item to the header's
More menu while a turn runs (`key chat-thread-stop-menu`). It is shown on every
platform, so touch devices without a keyboard can stop.
- **Tasks spinner.** `chat_task_spinner.dart` turns the layers icon once per
2.5 s while at least one background task runs; static otherwise and under
reduced motion. Automation-only state keeps its static schedule icon.
- **Tasks spinner.** Superseded: `chat_task_spinner.dart` now draws a progress
ring with the running count instead of turning the layers icon. See
`notes/background-tasks-ring.md`.
## Focused tests (memwatch, from app/)
@@ -673,11 +673,18 @@ void main() {
});
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(find.byTooltip('2 tasks, 12 automations'), findsOneWidget);
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
final counter = find.byKey(const Key('chat-background-tasks-button'));
// One '2' is the count inside the ring, one is the compact caption.
expect(
tester
.widget<Text>(find.byKey(const Key('chat-background-tasks-count')))
.data,
'2',
);
expect(
find.descendant(of: counter, matching: find.text('2')),
findsOneWidget,
findsNWidgets(2),
);
expect(
find.descendant(of: counter, matching: find.text('12')),
@@ -6,19 +6,23 @@ import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_background_tasks.dart';
import 'package:pipelines_app/features/chat/conversation/chat_task_spinner.dart';
RotationTransition _rotation(WidgetTester tester) =>
tester.widget<RotationTransition>(
find.byKey(const Key('chat-background-tasks-spinner')),
final _spinnerFinder = find.byKey(const Key('chat-background-tasks-spinner'));
CircularProgressIndicator _ring(WidgetTester tester) =>
tester.widget<CircularProgressIndicator>(
find.descendant(
of: _spinnerFinder,
matching: find.byType(CircularProgressIndicator),
),
);
Widget _spinner(bool spinning) => MaterialApp(
home: Scaffold(
body: ChatTaskSpinner(
spinning: spinning,
child: const Icon(Icons.layers_outlined, size: 16),
),
),
);
Widget _spinner(int running, {Brightness brightness = Brightness.light}) =>
MaterialApp(
theme: ThemeData(colorSchemeSeed: Colors.indigo, brightness: brightness),
home: Scaffold(
body: Center(child: ChatTaskSpinner(running: running)),
),
);
void _reducedMotion(bool reduced) =>
TestWidgetsFlutterBinding.ensureInitialized()
@@ -51,58 +55,99 @@ class _TasksGateway implements ApiGateway {
void main() {
tearDown(() => _reducedMotion(false));
testWidgets('turns once every period while spinning', (tester) async {
testWidgets(
'a running task shows an indeterminate primary ring with the count',
(tester) async {
_reducedMotion(false);
await tester.pumpWidget(_spinner(2));
final ring = _ring(tester);
expect(ring.value, isNull);
expect(ring.strokeWidth, 2);
expect(
ring.color,
ThemeData(colorSchemeSeed: Colors.indigo).colorScheme.primary,
);
expect(
find.descendant(of: _spinnerFinder, matching: find.text('2')),
findsOneWidget,
);
expect(
find.descendant(
of: _spinnerFinder,
matching: find.byIcon(Icons.layers_outlined),
),
findsNothing,
);
// The ring keeps turning: time advances the animation.
await tester.pump(const Duration(milliseconds: 300));
expect(tester.binding.transientCallbackCount, greaterThan(0));
await tester.pumpWidget(const SizedBox.shrink());
expect(tester.binding.transientCallbackCount, 0);
},
);
testWidgets('dark theme uses the dark primary for the ring', (tester) async {
_reducedMotion(false);
await tester.pumpWidget(_spinner(true));
expect(_rotation(tester).turns.value, 0);
await tester.pump(ChatTaskSpinner.period ~/ 4);
expect(_rotation(tester).turns.value, closeTo(0.25, 0.01));
// Past one full lap the turn starts again from the top.
await tester.pump(
ChatTaskSpinner.period ~/ 4 * 3 + const Duration(milliseconds: 100),
await tester.pumpWidget(_spinner(1, brightness: Brightness.dark));
expect(
_ring(tester).color,
ThemeData(
colorSchemeSeed: Colors.indigo,
brightness: Brightness.dark,
).colorScheme.primary,
);
expect(_rotation(tester).turns.value, closeTo(0.04, 0.01));
await tester.pumpWidget(const SizedBox.shrink());
expect(tester.binding.transientCallbackCount, 0);
});
testWidgets('stays still when not spinning, and stops when it stops', (
testWidgets('no running task shows the static icon with no ring', (
tester,
) async {
_reducedMotion(false);
await tester.pumpWidget(_spinner(false));
await tester.pump(const Duration(seconds: 2));
expect(_rotation(tester).turns.value, 0);
expect(tester.binding.transientCallbackCount, 0);
await tester.pumpWidget(_spinner(true));
await tester.pump(const Duration(milliseconds: 625));
expect(_rotation(tester).turns.value, greaterThan(0));
await tester.pumpWidget(_spinner(false));
await tester.pump();
expect(_rotation(tester).turns.value, 0);
await tester.pump(const Duration(seconds: 2));
expect(_rotation(tester).turns.value, 0);
await tester.pumpWidget(_spinner(0));
expect(
find.descendant(
of: _spinnerFinder,
matching: find.byType(CircularProgressIndicator),
),
findsNothing,
);
expect(
find.descendant(
of: _spinnerFinder,
matching: find.byIcon(Icons.layers_outlined),
),
findsOneWidget,
);
expect(tester.binding.transientCallbackCount, 0);
});
testWidgets('reduced motion keeps the icon static even while spinning', (
testWidgets('every state keeps the same square size', (tester) async {
_reducedMotion(false);
for (final running in [0, 1, 12]) {
await tester.pumpWidget(_spinner(running));
expect(tester.getSize(_spinnerFinder), const Size(16, 16));
}
});
testWidgets('reduced motion holds one static ring segment while running', (
tester,
) async {
_reducedMotion(true);
await tester.pumpWidget(_spinner(true));
await tester.pumpWidget(_spinner(3));
expect(_ring(tester).value, ChatTaskSpinner.reducedSegment);
await tester.pump(const Duration(seconds: 1));
expect(_rotation(tester).turns.value, 0);
expect(_ring(tester).value, ChatTaskSpinner.reducedSegment);
expect(tester.binding.transientCallbackCount, 0);
});
testWidgets('the tasks icon rotates only while a task runs', (tester) async {
testWidgets('the composer button shows the count ring and its tooltip', (
tester,
) async {
_reducedMotion(false);
final gateway = _TasksGateway();
addTearDown(gateway.close);
gateway.running = const [
{'id': 'sh1', 'status': 'running', 'command': 'go test ./...'},
{'id': 'sh2', 'status': 'running', 'command': 'make'},
];
await tester.pumpWidget(
MaterialApp(
@@ -111,12 +156,15 @@ void main() {
),
),
);
// The spinning icon repeats forever, so settle by pumping, never by waiting.
// The ring repeats forever, so settle by pumping, never by waiting.
await tester.pump();
await tester.pump();
expect(find.text('1 task'), findsOneWidget);
final before = _rotation(tester).turns.value;
await tester.pump(const Duration(milliseconds: 300));
expect(_rotation(tester).turns.value, greaterThan(before));
expect(find.text('2 tasks'), findsOneWidget);
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
expect(_ring(tester).value, isNull);
expect(
find.descendant(of: _spinnerFinder, matching: find.text('2')),
findsOneWidget,
);
});
}