7b045e5aab
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.8 KiB
Dart
50 lines
1.8 KiB
Dart
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();
|
|
}
|
|
|
|
/// The indicator rebuilds on every animation frame. A rebuild under an
|
|
/// enclosing [LayoutBuilder] (a list row's) marks that builder for layout,
|
|
/// and a row in a list then relays the whole list out on every frame. Under
|
|
/// its own builder the rebuild lays out only this spinner (and, under loose
|
|
/// constraints, its parents up to the nearest relayout boundary); in a fixed
|
|
/// square, as in chat rows, it stops at the spinner.
|
|
@override
|
|
Widget build(BuildContext context) => LayoutBuilder(
|
|
builder: (context, _) => CircularProgressIndicator(
|
|
controller: _controller,
|
|
strokeWidth: widget.strokeWidth,
|
|
),
|
|
);
|
|
}
|