Files
alan 1be2418892 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>
2026-11-22 18:19:22 +00:00

60 lines
1.6 KiB
Dart

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).
///
/// Every action gets the platform's whole touch target and no extra padding,
/// so a row of them is evenly spaced and the last one never touches the
/// pill's edge: Material's [IconButton] (48dp, with its tooltip).
/// While [busy] the action shows the platform's activity indicator in the
/// same box and takes no taps.
class BarIconButton extends StatelessWidget {
const BarIconButton({
super.key,
required this.icon,
required this.label,
required this.onPressed,
this.selected = false,
this.busy = false,
this.busyLabel,
});
final IconData icon;
/// The tooltip and accessible name.
final String label;
final VoidCallback? onPressed;
/// Material shows a toggled-on action as selected.
final bool selected;
final bool busy;
/// The accessible name while [busy]; defaults to [label].
final String? busyLabel;
@override
Widget build(BuildContext context) {
if (busy) {
return Semantics(
label: busyLabel ?? label,
liveRegion: true,
child: const SizedBox.square(
dimension: kMinInteractiveDimension,
child: Center(
child: SizedBox.square(
dimension: 20,
child: AppSpinner(strokeWidth: 2),
),
),
),
);
}
return IconButton(
tooltip: label,
isSelected: selected,
onPressed: onPressed,
icon: Icon(icon),
);
}
}