Flutter docs
Default skin

Switch

Used to toggle between two states.

When to use

  • If you need to represent the switching between two states or on-off state.
  • The difference between Switch and Checkbox is that Switch will trigger a state change directly when you toggle it, while Checkbox is generally used for state marking, which should work in conjunction with submit operation.

Examples

Basic

The most basic usage.

Text & icon

With text and icon.

Loading

Mark a pending state of switch.

Disabled

Disabled state of Switch.

Two sizes

size="small" represents a small sized switch.

Custom semantic dom styling

You can customize the semantic dom style of Switch by passing objects/functions through classNames and styles.

API

Switch and its props are exported from @ceebee/ui/client.

Switch

PropertyDescriptionTypeDefaultVersion
checkedDetermine whether the Switch is checkedbooleanfalse—
checkedChildrenThe content to be shown when the state is checkedReactNode-—
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-—
defaultCheckedWhether to set the initial statebooleanfalse—
defaultValueAlias for defaultCheckedboolean-5.12.0
disabledDisable switchbooleanfalse—
loadingLoading state of switchbooleanfalse—
sizeThe size of the Switch, options: medium small'medium' | 'small'medium—
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-—
unCheckedChildrenThe content to be shown when the state is uncheckedReactNode-—
valueAlias for checkedboolean-5.12.0
onChangeTrigger when the checked state is changingfunction(checked: boolean, event: Event)-—
onClickTrigger when clickedfunction(checked: boolean, event: Event)-—
blur()Remove focus———
focus()Get focus———