ToggleSwitch
A Fluent toggle switch, for turning an option on or off with an immediate effect.
Example:
fluent.ToggleSwitch(label="Wi-Fi", value=True)
fluent.ToggleSwitch(label="Bluetooth")

Inherits: LayoutControl
Example
Fluent ToggleSwitch
import flet_fluent_ui as fluent
import flet as ft
def main(page: ft.Page):
page.title = "Fluent ToggleSwitch"
def handle_change(e: ft.Event[fluent.ToggleSwitch]):
status.value = "Wi-Fi is on" if e.control.value else "Wi-Fi is off"
status = ft.Text("Wi-Fi is off")
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
fluent.ToggleSwitch(label="Wi-Fi", on_change=handle_change),
fluent.ToggleSwitch(
label="Bluetooth", label_first=True, value=True
),
fluent.ToggleSwitch(label="Disabled", disabled=True),
status,
],
)
)
)
if __name__ == "__main__":
ft.run(main)

Properties
autofocusclass-attributeinstance-attribute
autofocus: bool = FalseWhether this switch should be focused on initial display.
labelclass-attributeinstance-attribute
label: StrOrControl | None = NoneThe label shown next to this switch. Clicking it toggles the switch.
Events
on_changeclass-attributeinstance-attribute
on_change: ControlEventHandler[ToggleSwitch] | None = (
None
)Called when value changes.
The data property of the event handler argument
contains the new value.