9adee6cc60
Keep the public Cupertino-compatible parameters while retaining only the Material implementations and tests. The app is Material-only, so deleting unreachable Cupertino branches reduces dead code without changing the active path.
65 lines
1.7 KiB
Dart
65 lines
1.7 KiB
Dart
import 'package:flutter/material.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.cupertinoIcon,
|
|
required this.label,
|
|
required this.onPressed,
|
|
this.selected = false,
|
|
this.busy = false,
|
|
this.busyLabel,
|
|
this.cupertino,
|
|
});
|
|
|
|
final IconData icon;
|
|
final IconData cupertinoIcon;
|
|
|
|
/// 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;
|
|
|
|
/// The control family; defaults to the host's.
|
|
final bool? cupertino;
|
|
|
|
@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: CircularProgressIndicator(strokeWidth: 2),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
return IconButton(
|
|
tooltip: label,
|
|
isSelected: selected,
|
|
onPressed: onPressed,
|
|
icon: Icon(icon),
|
|
);
|
|
}
|
|
}
|