CupertinoSwitch
An iOS-style switch.
Used to toggle the on/off state of a single setting.
Example:
ft.CupertinoSwitch(value=True)

Inherits: LayoutControl
Properties
active_thumb_image_src- An image to use on the thumb of this switch when the switch is on.active_track_color- The color to use on the track when this switch is on.autofocus- Whether this switch will be selected as the initial focus.focus_color- The color to use for the focus highlight for keyboard interactions.inactive_thumb_color- The color to use on the thumb when this switch is off.inactive_thumb_image_src- An image to use on the thumb of this switch when the switch is off.inactive_track_color- The color to use on the track when this switch is off.label- The clickable label to display on the right of this switch.label_position- The position of thelabelrelative to this switch.off_label_color- The color to use for the accessibility label when the switch is off.thumb_color- The color of this switch's thumb.thumb_icon- The icon of this Switch's thumb in variousControlStates.track_outline_color- The outline color of this switch's track in variousControlStates.track_outline_width- The outline width of this switch's track in all or specificControlStates.value- The current value of this switch.
Events
on_blur- Called when this switch has lost focus.on_change- Called when the state of this switch is changed.on_focus- Called when this switch has received focus.on_image_error- Called whenactive_thumb_image_srcorinactive_thumb_image_srcfails to load.on_label_color- The color to use for the accessibility label when the switch is on.
Examples
Cupertino, Material and Adaptive Switches
play_arrowTry Online
import flet as ft
def main(page: ft.Page):
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.CupertinoSwitch(label="Cupertino Switch", value=True),
ft.Switch(
label="Material Switch",
value=True,
thumb_color={ft.ControlState.SELECTED: ft.Colors.BLUE},
track_color=ft.Colors.YELLOW,
focus_color=ft.Colors.PURPLE,
),
ft.Container(height=20),
ft.Text(
value=(
"Adaptive Switch shows as CupertinoSwitch on macOS and "
"iOS and as Switch on other platforms:"
)
),
ft.Switch(adaptive=True, label="Adaptive Switch", value=True),
],
),
)
)
if __name__ == "__main__":
ft.run(main)

Properties
active_thumb_image_srcclass-attributeinstance-attribute
active_thumb_image_src: str | bytes | None = NoneAn image to use on the thumb of this switch when the switch is on.
It can be one of the following:
- A URL or local asset file path;
- A base64 string;
- Raw bytes.