GlassSwitch class Panels and controls

A switch whose knob becomes a clear glass drop while it is held.

At rest it is iOS's switch: a track of kGlassSwitchSize in trackColor or activeColor, and an opaque white knob that is not glass at all. A tap toggles it; a horizontal drag carries the knob and commits on release, on whichever side of the middle it was let go. While a finger is down the knob is a clear drop dropScale times its size that minifies the track under it by dropWiden.

The switch holds no value of its own: onChanged is told the new one and the caller passes it back as value.

Space or Enter toggles a focused switch, and the focus ring is drawn around its track. Under TextDirection.rtl it is mirrored: on is to the left.

MergeSemantics(
  child: Row(
    children: <Widget>[
      const Expanded(child: Text('Wi-Fi')),
      GlassSwitch(
        value: wifi,
        onChanged: (bool on) => setState(() => wifi = on),
      ),
    ],
  ),
)

Note: what a held switch costs is one capture when the drop appears and none while it moves: the drop moves inside a GlassTravel region of its own, and the track changes colour only when the value commits.

See also:

Inheritance

Constructors

GlassSwitch({required bool value, required ValueChanged<bool>? onChanged, Color? activeColor, Color? trackColor, double dropScale = kGlassDropScale, double dropWiden = kGlassSwitchDropWiden, GlassDropMotion? dropMotion, String? semanticLabel, FocusNode? focusNode, bool autofocus = false, Key? key})
A switch showing value, reporting a change through onChanged — null to disable it.
const

Properties

activeColor → Color?
The track when on. Null for iOS's systemGreen in the appearance of the label around the switch: on glass, the glass's.
final
autofocus → bool
Whether the switch takes the focus as soon as it is built.
final
dropMotion → GlassDropMotion?
How the held drop deforms as it launches and brakes. Null takes GlassThemeData.dropMotion; GlassDropMotion.none keeps its shape. Off under reduced motion either way.
final
dropScale → double
How much larger the held drop is than the resting knob. See kGlassDropScale; macOS's own switch is 1.6.
final
dropWiden → double
How much of the backdrop past its box the held drop shows, which minifies it. See kGlassSwitchDropWiden; 0 is a drop that does not.
final
focusNode → FocusNode?
The switch's focus. Null makes one the switch owns.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onChanged → ValueChanged<bool>?
Null disables the switch, which is also what the semantics say; it is then drawn at kGlassDisabledOpacity.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
semanticLabel → String?
What a screen reader says the switch is for. Null leaves it to a MergeSemantics around the switch and its row's label.
final
trackColor → Color?
The track when off. Null for iOS's secondarySystemFill in that appearance.
final
value → bool
Whether the switch is on. The knob slides to it when it changes, unless a finger is dragging it.
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<GlassSwitch>
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