Button group
Group a few commands that operate on the same thing. A toolbar suits repeated actions such as changing the zoom of a document.
Adjust zoom
#Use Out or In to change the zoom by ten percentage points. The current value appears below the controls.
components/button-group/appliance/adjust_zoom.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
import 'package:flutter/cupertino.dart' show CupertinoIcons;
class AdjustZoom extends StatefulWidget {
const AdjustZoom({super.key});
@override
State<AdjustZoom> createState() => _AdjustZoomState();
}
class _AdjustZoomState extends State<AdjustZoom> {
int zoom = 100;
@override
Widget build(BuildContext context) => Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceToolbar(
semanticLabel: 'Zoom',
children: [
ApplianceIconButton(
icon: const Icon(CupertinoIcons.minus),
semanticLabel: 'Zoom out',
onPressed: zoom > 10 ? () => setState(() => zoom -= 10) : null,
),
ApplianceIconButton(
icon: const Icon(CupertinoIcons.plus),
semanticLabel: 'Zoom in',
onPressed: () => setState(() => zoom += 10),
),
],
),
const SizedBox(height: 12),
Text('Zoom: $zoom%'),
],
);
}
Parameters
ApplianceToolbar API ↗children- Zoom commands in reading order.
semanticLabel- Names the group for assistive technology.
Shared behaviour
- Keyboard and focus. Use Tab to reach the group. Depending on the look, move between its controls with Tab or the horizontal arrows, then activate the desired command.
- Screen readers. The commands have separate names. Read the percentage below the group to check the result.
- Direction and type. The pair follows reading order. Try the phone preview at 200% to see how each command fits its button.