Skip to main content

Switch

The Stac Switch widget allows you to build the Flutter Switch widget using JSON. To know more about the Switch widget in Flutter, refer to the official documentation.

Properties​

PropertyTypeDescription
switchTypeStacSwitchTypeThe type of the Switch.
valueboolWhether this switch is on or off.
onChangedMap<String, dynamic>Called when the user toggles the switch on or off.
autofocusboolTrue if this widget will be selected as the initial focus when no other node in its scope is currently focused.
activeColorStringThe color to use when this switch is on.
activeTrackColorStringThe color to use on the track when this switch is on.
focusColorStringThe color for the button's when it has the input focus.
hoverColorStringThe color for the button's when a pointer is hovering over it.
inactiveThumbColorStringThe color to use on the thumb when this switch is off.
inactiveTrackColorStringThe color to use on the track when this switch is off.
onLabelColorStringThe color to use for the accessibility label when the switch is on.
offLabelColorStringThe color to use for the accessibility label when the switch is off.
splashRadiusdoubleThe splash radius of the circular ink response.
dragStartBehaviorDragStartBehaviorDetermines the way that drag start behavior is handled.
overlayColorStacMaterialColorThe color for the switch.
thumbColorStacMaterialColorThe color of this Switch's thumb.
trackColorStacMaterialColorTThe color of this Switch's track.
materialTapTargetSizeMaterialTapTargetSizeConfigures the minimum size of the tap target.
trackOutlineColorStacMaterialColorThe outline color of this Switch's track.
thumbIconMap<String, dynamic>The icon to use on the thumb of this switch.
inactiveThumbImageStringAn image to use on the thumb of this switch when the switch is off.
activeThumbImageStringAn image to use on the thumb of this switch when the switch is on.
applyThemeboolWhether to apply the ambient theme data.
applyCupertinoThemeboolWhether to apply the ambient theme data.

Example JSON​

Example 1: Cupertino Switch​

{
"type": "switch",
"switchType": "cupertino",
"value": true
}

Example 2: Adaptive Switch​

{
"type": "switch",
"switchType": "adaptive",
"value": true
}

Example 3: Material Switch​

{
"type": "switch",
"switchType": "material",
"value": false
}