Switch
PaymentSwitch turns a setting on or off immediately, such as “Refund alerts”. The switch sits at the end of the row, and the whole row is the target.



Minimal
Section titled “Minimal”Add the published package, then paste this complete example into lib/main.dart.
import 'package:flutter/material.dart';import 'package:rakit_ui/rakit_ui.dart';
void main() => runApp(const MaterialApp(home: SettingsPage()));
class SettingsPage extends StatefulWidget { const SettingsPage({super.key}); @override State<SettingsPage> createState() => _SettingsPageState();}
class _SettingsPageState extends State<SettingsPage> { bool alerts = false; @override Widget build(BuildContext context) => Scaffold( appBar: AppBar(title: const Text('Example')), body: PaymentSwitch( label: 'Email alerts', value: alerts, onChanged: (value) => setState(() => alerts = value), ), );}Variants
Section titled “Variants”Variants: off, on.
Switch or checkbox
Section titled “Switch or checkbox”Use a switch when the change applies the moment it is flipped, like a setting. Use a checkbox when the choice is only applied after a button press, such as “Save this card” before paying.
On and off
Section titled “On and off”When on, the track fills with the accent and the thumb moves to the end and shows a check. When off, the track is the surface with a border edge. Position and the check carry the state, so it is never color alone.
Disabled
Section titled “Disabled”Pass onChanged: null. The track turns surfaceMuted, the label turns muted, and taps do nothing. Pass disabledReason; it replaces description while the row is disabled.
const PaymentSwitch( value: false, onChanged: null, label: 'Weekly summary', disabledReason: 'Turn on notifications in Settings',);Behavior, states and migration
Section titled “Behavior, states and migration”errorText shows an icon, danger caption and off-track danger edge. Required is spoken, with gating owned by the host. HiddenElements retains hidden text in semantics. Use a switch for an immediate setting, not consent applied after a later submit.
Which variant when
Section titled “Which variant when”| Situation | Variant / composition | Payment example |
|---|---|---|
| Promotion notifications | off | Use for independent persistent preferences, with the label centered to the mark. |
Use Radio for default method choices.
States
Section titled “States”The host supplies the on/off value. Disable the control while a change cannot be accepted and keep its explanation readable.
Do and don’t
Section titled “Do and don’t”Do: Use for independent persistent preferences, with the label centered to the mark.
Don’t: Use a switch to start a one-time payment action.
Content guidelines
Section titled “Content guidelines”- Name the setting, not the action: “Refund alerts”, not “Turn on refund alerts”.
- Use the description for what the setting does when on.
- If applying the setting can fail, show the switch in its old position and tell people with a toast.
Accessibility
Section titled “Accessibility”- The whole row is one target and one screen-reader node, announced as a toggle that is on or off.
- The painted switch takes no focus of its own; one Tab reaches the row. Keyboard focus draws the kit’s focus ring.
The switch mark centers on the first label line; the row retains its minimum touch target.
In the example app
Section titled “In the example app”

PaymentSwitch
class PaymentSwitch extends StatelessWidget · lib/src/controls/controls.dart
An on/off setting that takes effect at once, such as "Notify me about refunds". For a choice that is only applied after a button press, use a PaymentCheckbox instead.
The switch sits at the end of the row; the whole row is the target. The thumb moves and shows a check when on, so the state is never carried by color alone.
| Parameter | Type | Default | Description |
|---|---|---|---|
value:required | bool | — | — |
onChanged:required | ValueChanged<bool>? | — | — |
label:required | String | — | — |
description: | String? | — | — |
disabledReason: | String? | — | Replaces description while the row is disabled. |
errorText: | String? | — | Validation message, with a danger icon and edge. |
required: | bool | false | Spoken as required; the host gates the next step. |
hiddenElements: | Set<PaymentFieldPart> | const {} | Visually hidden parts remain in semantics. |
PaymentFieldPart
enum PaymentFieldPart · lib/src/foundation/payment_tokens.dart
A hidden field part stays in semantics; consumers arrive in later phases.
| Value | Description |
|---|---|
label | Label field part. |
description | Description field part. |
error | Error field part. |
See also
Section titled “See also”- Checkbox for choices applied with a button.
- Action tile for settings rows that open another screen.