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, ); } }