Skip to main content

Switch & Toggle

Switch uses native platform controls (UISwitch on iOS, SwitchCompat on Android). Toggle is a Drift-rendered on/off control.

Switch

// Native switch (use struct literal, no themed constructor)
widgets.Switch{
Value: isEnabled,
OnTintColor: colors.Primary,
OnChanged: func(value bool) {
s.SetState(func() {
isEnabled = value
})
},
}

Switch Properties

PropertyTypeDescription
ValueboolCurrent on/off state
OnChangedfunc(bool)Called when toggled
DisabledboolDisables interaction when true
OnTintColorgraphics.ColorTrack color when on
ThumbColorgraphics.ColorThumb color

Toggle

// Themed (recommended)
theme.ToggleOf(ctx, isEnabled, func(value bool) {
s.SetState(func() {
isEnabled = value
})
})

// Explicit
widgets.Toggle{
Value: isEnabled,
ActiveColor: colors.Primary,
InactiveColor: colors.SurfaceVariant,
OnChanged: func(value bool) {
s.SetState(func() {
isEnabled = value
})
},
}

Toggle Properties

PropertyTypeDescription
ValueboolCurrent on/off state
ActiveColorgraphics.ColorTrack color when on
InactiveColorgraphics.ColorTrack color when off
OnChangedfunc(bool)Called when toggled

Switch vs Toggle

SwitchToggle
RenderingNative platform controlDrift-rendered
Themed constructorNotheme.ToggleOf
Look and feelMatches OS styleConsistent across platforms