Replace background task spinner with gear
Use an outlined settings gear with a running-count badge and slow linear rotation while background tasks are active. Preserve reduced-motion behavior, composer sizing, and tooltip coverage with updated focused tests and notes.
This commit is contained in:
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'chat_background_tasks_controller.dart';
|
||||
import 'chat_background_tasks_dialog.dart';
|
||||
import 'chat_task_spinner.dart';
|
||||
import 'chat_task_gear.dart';
|
||||
|
||||
/// Compact live task count: a quiet control inside the composer beside Send,
|
||||
/// shown only while tasks run. Details live only in its modal.
|
||||
@@ -147,11 +147,11 @@ class _ChatBackgroundTasksState extends State<ChatBackgroundTasks> {
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
onPressed: _open,
|
||||
// A ring around the running count while tasks run; automations stay
|
||||
// A turning gear with a count badge while tasks run; automations stay
|
||||
// on their static schedule icon.
|
||||
icon: automationOnly
|
||||
? const Icon(Icons.schedule, size: 16)
|
||||
: ChatTaskSpinner(running: count),
|
||||
: ChatTaskGear(running: count),
|
||||
label: caption(),
|
||||
);
|
||||
return Padding(
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
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.
|
||||
class ChatTaskGear extends StatefulWidget {
|
||||
const ChatTaskGear({super.key, required this.running, this.size = 16});
|
||||
|
||||
final int running;
|
||||
final double size;
|
||||
|
||||
/// Time for one full turn while tasks run.
|
||||
static const Duration turnDuration = Duration(seconds: 4);
|
||||
|
||||
@override
|
||||
State<ChatTaskGear> createState() => _ChatTaskGearState();
|
||||
}
|
||||
|
||||
class _ChatTaskGearState extends State<ChatTaskGear>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _spin = AnimationController(
|
||||
vsync: this,
|
||||
duration: ChatTaskGear.turnDuration,
|
||||
);
|
||||
bool? _spinning;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_sync();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatTaskGear oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
_sync();
|
||||
}
|
||||
|
||||
/// Turns the gear only while tasks run and motion is allowed. Stopping
|
||||
/// resets to the upright position, so an idle gear is always the same glyph.
|
||||
void _sync() {
|
||||
final reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
||||
final spinning = widget.running > 0 && !reduced;
|
||||
if (spinning == _spinning) return;
|
||||
_spinning = spinning;
|
||||
if (spinning) {
|
||||
_spin.repeat();
|
||||
} else {
|
||||
_spin.stop();
|
||||
_spin.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_spin.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@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),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 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 int running;
|
||||
final double size;
|
||||
|
||||
/// Fraction of the ring drawn while reduced motion holds it still.
|
||||
static const double reducedSegment = 0.25;
|
||||
|
||||
@override
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user