Switch
A switch changes a setting immediately. Use a label that names the setting and keep it stable when the value changes.
Set reminders
#Turn reminders on, then off. The message below the switch shows the current setting.
components/switch/appliance/set_reminders.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class SetReminders extends StatefulWidget {
const SetReminders({super.key});
@override
State<SetReminders> createState() => _SetRemindersState();
}
class _SetRemindersState extends State<SetReminders> {
bool reminders = false;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceSwitch(
semanticLabel: 'Reminders',
value: reminders,
onChanged: (next) => setState(() => reminders = next),
),
const SizedBox(height: 12),
Text(reminders ? 'Reminders on' : 'Reminders off'),
],
),
);
}
Parameters
ApplianceSwitch API ↗semanticLabel- Names the setting in both states.
value- Whether reminders are on.
onChanged- Applies the new setting immediately.
Shared behaviour
- Keyboard and focus. Tab to the switch and press Space. The same control turns the setting back off.
- Screen readers. Read the Reminders label and the current state. The message after the switch spells out the resulting setting.
- Direction and type. Compare where the thumb rests in LTR and RTL. The message can wrap when the text size increases.