Segmented control
A segmented control offers a small set of mutually exclusive values. Keep the options short enough to compare at a glance.
Choose a reporting period
#Switch between Week and Month. The line below names the period included in the report.
components/segmented-control/appliance/choose_period.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class ChoosePeriod extends StatefulWidget {
const ChoosePeriod({super.key});
@override
State<ChoosePeriod> createState() => _ChoosePeriodState();
}
class _ChoosePeriodState extends State<ChoosePeriod> {
String period = 'Week';
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceSegmentedButton<String>(
segments: const [
ApplianceSegment(value: 'Week', label: 'Week'),
ApplianceSegment(value: 'Month', label: 'Month'),
],
semanticLabel: 'Reporting period',
value: period,
onChanged: (next) => setState(() => period = next),
),
const SizedBox(height: 12),
Text('Report period: $period'),
],
),
);
}
Parameters
ApplianceSegmentedButton API ↗segments- Available reporting periods in reading order.
value- Period currently selected.
onChanged- Receives the chosen period.
Shared behaviour
- Keyboard and focus. Tab to the options, then follow their focus indicator to change the period. Some looks move between segments with the arrows.
- Screen readers. Read the segment names and inspect which option is selected. The example also prints the chosen period.
- Direction and type. In RTL the options follow reading order. Try the phone width with larger text to inspect both labels.