Give running-turn spinners their own animation controller
Without one, CircularProgressIndicator looks its controller up on every frame, walking the widget tree for the ambient Theme (89 ms over a streamed reply at 4K). AppSpinner is the stock indicator with its own controller and the stock period. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -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<AppSpinner> createState() => _AppSpinnerState();
|
||||
}
|
||||
|
||||
class _AppSpinnerState extends State<AppSpinner>
|
||||
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,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user