Radio group
Use radio buttons for one answer among a few visible alternatives. Keeping both choices in view makes their differences easy to compare.
Choose a delivery method
#Choose Pickup or Courier. Only one delivery method is current, and the confirmation repeats it.
components/radio-group/appliance/choose_delivery.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class ChooseDelivery extends StatefulWidget {
const ChooseDelivery({super.key});
@override
State<ChooseDelivery> createState() => _ChooseDeliveryState();
}
class _ChooseDeliveryState extends State<ChooseDelivery> {
String delivery = 'Pickup';
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Delivery method'),
const SizedBox(height: 12),
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final name in const ['Pickup', 'Courier'])
Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
children: [
ApplianceRadio<String>(
value: name,
groupValue: delivery,
semanticLabel: name,
onChanged: (value) => setState(() => delivery = value),
),
// The radio already announces this visible label.
ExcludeSemantics(child: Text(name)),
],
),
],
),
],
),
const SizedBox(height: 12),
Text('Delivery: $delivery'),
],
),
);
}
Parameters
ApplianceRadio API ↗semanticLabel- Spoken name of this option.
value- Value represented by this radio.
groupValue- Value currently shared by the group.
onChanged- Updates the current delivery method.
Shared behaviour
- Keyboard and focus. Use Tab to enter the choices. Try the arrow keys in groups with roving focus, or Tab and Space on individually focusable radios.
- Screen readers. Each choice has a distinct name and a checked state. Read the confirmation after the group to hear the chosen delivery method.
- Direction and type. The options follow reading order. Try both directions and larger type on the phone to inspect the labels beside their controls.