Drop the count badge from the background tasks gear

The caption beside the gear already says how many tasks run.
This commit is contained in:
2026-11-12 14:12:34 +00:00
parent 45f5323c75
commit ff39114e4f
3 changed files with 19 additions and 59 deletions
@@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
/// Background-task glyph for the composer: an outlined settings gear. While
/// [running] is above zero the gear turns slowly and steadily (linear, one
/// turn per [turnDuration]) and a small Material [Badge] shows the count.
/// With no running task the gear is static and carries no badge. With reduced
/// motion the gear never rotates but the badge still shows. Always [size]
/// square so the button keeps the same dimensions in every state.
/// turn per [turnDuration]). The running count is already written beside it
/// ("1 task"), so the gear carries no count of its own. With no running task,
/// or with reduced motion, the gear is static. Always [size] square so the
/// button keeps the same dimensions in every state.
class ChatTaskGear extends StatefulWidget {
const ChatTaskGear({super.key, required this.running, this.size = 16});
@@ -62,25 +62,13 @@ class _ChatTaskGearState extends State<ChatTaskGear>
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final running = widget.running;
return SizedBox.square(
key: const Key('chat-background-tasks-gear'),
dimension: widget.size,
child: Badge(
key: const Key('chat-background-tasks-badge'),
isLabelVisible: running > 0,
backgroundColor: theme.colorScheme.primary,
textColor: theme.colorScheme.onPrimary,
label: Text(
'$running',
key: const Key('chat-background-tasks-count'),
),
child: RotationTransition(
key: const Key('chat-background-tasks-rotation'),
turns: _spin,
child: Icon(Icons.settings_outlined, size: widget.size),
),
child: RotationTransition(
key: const Key('chat-background-tasks-rotation'),
turns: _spin,
child: Icon(Icons.settings_outlined, size: widget.size),
),
);
}
@@ -675,16 +675,14 @@ void main() {
await tester.pump(const Duration(milliseconds: 500));
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
final counter = find.byKey(const Key('chat-background-tasks-button'));
// One '2' is the count on the gear badge, one is the compact caption.
// The compact caption carries the count; the gear has none of its own.
expect(
tester
.widget<Text>(find.byKey(const Key('chat-background-tasks-count')))
.data,
'2',
find.byKey(const Key('chat-background-tasks-count')),
findsNothing,
);
expect(
find.descendant(of: counter, matching: find.text('2')),
findsNWidgets(2),
findsOneWidget,
);
expect(
find.descendant(of: counter, matching: find.text('12')),
@@ -7,14 +7,11 @@ import 'package:pipelines_app/features/chat/conversation/chat_background_tasks.d
import 'package:pipelines_app/features/chat/conversation/chat_task_gear.dart';
final _gearFinder = find.byKey(const Key('chat-background-tasks-gear'));
final _badgeFinder = find.byKey(const Key('chat-background-tasks-badge'));
final _rotationFinder = find.byKey(const Key('chat-background-tasks-rotation'));
RotationTransition _rotation(WidgetTester tester) =>
tester.widget<RotationTransition>(_rotationFinder);
Badge _badge(WidgetTester tester) => tester.widget<Badge>(_badgeFinder);
Widget _gear(int running, {Brightness brightness = Brightness.light}) =>
MaterialApp(
theme: ThemeData(colorSchemeSeed: Colors.indigo, brightness: brightness),
@@ -54,16 +51,16 @@ class _TasksGateway implements ApiGateway {
void main() {
tearDown(() => _reducedMotion(false));
testWidgets('a running task shows the outlined gear with a count badge', (
testWidgets('a running task shows the outlined gear with no count on it', (
tester,
) async {
_reducedMotion(false);
await tester.pumpWidget(_gear(2));
expect(_badge(tester).isLabelVisible, isTrue);
expect(
find.descendant(of: _gearFinder, matching: find.text('2')),
findsOneWidget,
find.descendant(of: _gearFinder, matching: find.byType(Text)),
findsNothing,
);
expect(find.byType(Badge), findsNothing);
expect(
find.descendant(
of: _gearFinder,
@@ -98,12 +95,9 @@ void main() {
expect(ChatTaskGear.turnDuration, const Duration(seconds: 4));
});
testWidgets('an idle gear is static with no badge and no animation', (
tester,
) async {
testWidgets('an idle gear is static with no animation', (tester) async {
_reducedMotion(false);
await tester.pumpWidget(_gear(0));
expect(_badge(tester).isLabelVisible, isFalse);
expect(
find.descendant(
of: _gearFinder,
@@ -126,34 +120,15 @@ void main() {
await tester.pumpWidget(_gear(0));
expect(tester.binding.transientCallbackCount, 0);
expect(_rotation(tester).turns.value, closeTo(0, 1e-9));
expect(_badge(tester).isLabelVisible, isFalse);
});
testWidgets('reduced motion never rotates but still shows the count', (
tester,
) async {
testWidgets('reduced motion never rotates', (tester) async {
_reducedMotion(true);
await tester.pumpWidget(_gear(3));
expect(tester.binding.transientCallbackCount, 0);
await tester.pump(const Duration(seconds: 2));
expect(_rotation(tester).turns.value, closeTo(0, 1e-9));
expect(tester.binding.transientCallbackCount, 0);
expect(_badge(tester).isLabelVisible, isTrue);
expect(
find.descendant(of: _gearFinder, matching: find.text('3')),
findsOneWidget,
);
});
testWidgets('the badge uses the theme primary in dark mode', (tester) async {
_reducedMotion(false);
await tester.pumpWidget(_gear(1, brightness: Brightness.dark));
final scheme = ColorScheme.fromSeed(
seedColor: Colors.indigo,
brightness: Brightness.dark,
);
expect(_badge(tester).backgroundColor, scheme.primary);
expect(_badge(tester).textColor, scheme.onPrimary);
});
testWidgets('every state keeps the same square size', (tester) async {
@@ -186,10 +161,9 @@ void main() {
await tester.pump();
expect(find.text('2 tasks'), findsOneWidget);
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
expect(_badge(tester).isLabelVisible, isTrue);
expect(
find.descendant(of: _gearFinder, matching: find.text('2')),
findsOneWidget,
findsNothing,
);
expect(tester.binding.transientCallbackCount, greaterThan(0));
});