Skip to content
Get started
Menu
Get started

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.

Email, SMS and payment notification switches in enabled and disabled states.Email, SMS and payment notification switches in enabled and disabled states.
Switch
Email, SMS and payment notification switches in enabled and disabled states at 200 percent text.
200% text

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: off, on.

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.

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.

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',
);

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.

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.

The host supplies the on/off value. Disable the control while a change cannot be accepted and keep its explanation readable.

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.

  • 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.
  • 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.

Example account settings screen with synthetic dataExample account settings screen with synthetic data
Example: account settings

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.

ParameterTypeDefaultDescription
value:requiredbool——
onChanged:requiredValueChanged<bool>?——
label:requiredString——
description:String?——
disabledReason:String?—Replaces description while the row is disabled.
errorText:String?—Validation message, with a danger icon and edge.
required:boolfalseSpoken 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.

ValueDescription
labelLabel field part.
descriptionDescription field part.
errorError field part.
  • Checkbox for choices applied with a button.
  • Action tile for settings rows that open another screen.