MultiStateSwitch class

A switch-looking control with states fixed positions.

Two states behave like a regular on/off Switch, three give off / middle / on, and so on.

It is built on a discrete Slider, so dragging, snapping, tap-to-jump, keyboard input and semantics come for free. The track colour and thumb size move from "off" to "on" in proportion to the selected position.

Inheritance

Constructors

MultiStateSwitch({Key? key, required int states, required int value, required ValueChanged<int>? onChanged, Color? inactiveTrackColor, Color? activeTrackColor, Color? inactiveThumbColor, Color? activeThumbColor, double stepWidth = 24, Duration animationDuration = const Duration(milliseconds: 150), String semanticFormatterCallback(int state)?, FocusNode? focusNode, bool autofocus = false})
Creates a switch with states positions, currently at value.
const

Properties

activeThumbColor → Color?
Thumb colour in every position other than "off".
final
activeTrackColor → Color?
Track colour in the "on" position. Positions in between blend from inactiveTrackColor to this.
final
animationDuration → Duration
How long the track colour and thumb size take to follow a change.
final
autofocus → bool
See Slider.autofocus.
final
focusNode → FocusNode?
See Slider.focusNode.
final
hashCode → int
The hash code for this object.
no setterinherited
inactiveThumbColor → Color?
Thumb colour in the "off" position.
final
inactiveTrackColor → Color?
Track colour in the "off" position.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onChanged → ValueChanged<int>?
Called with the new position when the user picks one.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
semanticFormatterCallback → String Function(int state)?
Describes a position for screen readers. Defaults to the position number.
final
states → int
Number of positions the thumb can snap to. At least 2.
final
stepWidth → double
Distance between two neighbouring positions. The switch is 32 + (states - 1) * stepWidth wide.
final
value → int
Selected position, from 0 (off) to states - 1 (on).
final

Methods

build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
override
createElement() → StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
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