Switch class
A toggle for an immediate on/off setting — flipping it should take effect at once, with no separate save step.
Switch(
value: _wifiOn,
onChanged: (v) => setState(() => _wifiOn = v),
)
For a choice confirmed later by a form submit, prefer a checkbox.
- Inheritance
Constructors
-
Switch({Key? key, bool? value, bool? defaultValue, ValueChanged<
bool> ? onChanged, ControlSize? size, bool? disabled, bool readOnly = false, bool loading = false, String? semanticsLabel, Widget? checkedChild, Widget? uncheckedChild, SwitchToken? token, FocusNode? focusNode, bool autofocus = false}) -
Creates a Switch.
const
Properties
- autofocus → bool
-
Whether the switch takes focus as soon as it is built.
final
- checkedChild → Widget?
-
Small label shown inside the track when on.
final
- defaultValue → bool?
-
Which way an uncontrolled switch starts. Defaults to off.
final
- disabled → bool?
-
Greys the switch out and blocks toggling.
final
- focusNode → FocusNode?
-
A focus node of your own, for a switch whose focus you drive yourself.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loading → bool
-
Shows a spinner on the thumb and blocks toggling — for a setting whose
change is being persisted.
final
-
onChanged
→ ValueChanged<
bool> ? -
Called with the new state when toggled.
final
- readOnly → bool
-
Shows whether it is on without letting anyone flip it.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticsLabel → String?
-
What a screen reader calls this switch.
final
- size → ControlSize?
-
How tall the track is: a preset, or a height of your own.
final
- token → SwitchToken?
-
Per-instance token overrides.
final
- uncheckedChild → Widget?
-
Small label shown inside the track when off.
final
- value → bool?
-
Whether the switch is on. Null leaves the switch to drive itself (see
defaultValue).
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Switch> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited