Skip to content

Switch widgets let users turn a setting on or off. Choose the widget that fits your layout:

  • Switch: A standalone toggle.
  • SwitchListTile: A toggle with a title and an optional subtitle, such as a notification setting with explanatory text.
Switch on and off states beside SwitchListTile examples with titles, subtitles, and on and off toggles.Switch on and off states beside SwitchListTile examples with titles, subtitles, and on and off toggles.

Switch

Use Switch for a Boolean value, such as whether to receive email updates.

Adding Switch

Add a Switch widget from Base Elements or the widget tree. Then use Common Settings to configure its initial value, platform appearance, layout, and actions.

Customizing

Select the Switch widget and open Switch Properties in the properties panel.

Changing Color

The thumb is the sliding circle, and the track is the area it slides along.

Property Changes
Active Color Thumb color when on
Active Track Color Track color when on
Inactive Thumb Color Thumb color when off
Inactive Track Color Track color when off

See Change Color for ways to choose a color.

Disabled Colors

Use Disabled Active Color, Disabled Active Track Color, Disabled Inactive Thumb Color, and Disabled Inactive Track Color to style the corresponding on and off states while the switch is disabled.

Value Key

Assign a Value Key to identify the widget in automated tests. See Add Testing Value Key.

SwitchListTile

Use SwitchListTile when an on/off setting needs a title and an optional subtitle in the same row.

Adding SwitchListTile

  1. Add a SwitchListTile widget from Base Elements or the widget tree.
  2. In Title, set Text to name the setting.
  3. If the setting needs more context, enter explanatory text in Subtitle > Text.

Use Common Settings to configure its initial value, platform appearance, layout, and actions.

Customizing

Select the SwitchListTile widget and open Switch List Tile Properties in the properties panel.

Changing Switch Color

Property Changes
Tile Color Background color of the tile
Active Thumb Color Thumb color when on
Track Color Track color when on
Inactive Thumb Color Thumb color when off
Inactive Track Color Track color when off

See Change Color for ways to choose a color.

Layout and Spacing

  • Content Padding: Adjust the space around the contents inside the tile.
  • Border Radius: Round the tile’s corners. Set the corners together or adjust each corner separately.
  • Dense: Make the tile more compact.

Showing Switch at the Start

Turn on Leading to place the switch before the title.

Title and Subtitle

Expand Title or Subtitle to edit the text and its appearance. Both sections offer these controls:

  • Text: Enter the label or supporting description.
  • Theme Text Style: Choose a text style from your theme.
  • Font Family, Font Weight, Font Size, and Text Color: Customize the font and color.
  • Styling: Apply italics, underline, or strikethrough.
  • Line Height, Letter Spacing, and Text Align: Adjust text spacing and alignment.
  • Shadows: Select Add Shadow to add a text shadow.
  • Text Overflow Replacement: Choose how to display text that doesn’t fit.

Common Settings

These settings and behaviors apply to both Switch and SwitchListTile. Select the widget you want to configure in the properties panel.

Setting Platform Type

In Platform, choose a Platform Type:

  • Adaptive: Use iOS-style rendering on iOS and Android-style rendering on Android.
  • Android: Use Android-style rendering.

Setting Initial Value

Use Switch Initial Value to choose whether the switch starts on or off. To set it dynamically, select Set from Variable and choose a Boolean value, such as a Firestore field or an API response value.

Reading the Value

Open Set from Variable for the property or action input that needs the value. Choose Widget State, then select your Switch or SwitchListTile widget’s value.

For example, add a Text widget and bind its text to the widget’s value to display the current state.

Saving Switch Value

To save a change, add a save action under On Toggled On or On Toggled Off. Use On Toggled On for switching on and On Toggled Off for switching off. Configure both triggers if you need to save either change.

Shared Layout Controls

  • Expansion and Flex: Configure how the widget uses available space in its parent layout.
  • Padding: Set the space around the widget. You can set all sides together or adjust the left, top, right, and bottom values separately. See Padding.
  • Alignment: Position the widget within its available space. See Alignment.

Disable a Switch

Turn on Switch Disable Options, select Unset, and set a condition. When the condition evaluates to true, users can’t change the switch. For example, disable a device control when the device is unavailable.

Last updated on