GlassSegmentedControl class Panels and controls
A row of mutually exclusive segments; the selected one lifts into a clear glass drop while a finger is on it. See the file comment for what it costs.
The labels take the ambient DefaultTextStyle and IconTheme: the control
sits in the content layer, and its track is not glass. The selected one is
given an ink that reads on the capsule through the same two, so a segment
that is not an Icon or a Text reads IconTheme.of(context).color to
match.
The track is 32 px tall and takes the whole width it is given, split evenly between the segments; the control is laid out kGlassMinTapTarget tall so it takes taps above and below the track. A tap selects the segment pressed; a drag carries the drop and selects where it is let go. A focused control selects the segment beside the selected one on an arrow key.
Under TextDirection.rtl the first segment is at the right.
GlassSegmentedControl(
segments: const <Widget>[Text('Day'), Text('Week'), Text('Month')],
selectedIndex: range,
onSelected: (int i) => setState(() => range = i),
)
Note: at rest it costs nothing — the track and the capsule are paint. Held, the drop is one clear glass over a track that is not glass: the frames where it lifts and settles are captures, and a slide is drawn from the proxy already held.
Text size. The labels do not grow past the default text size, as
UIKit's UISegmentedControl does not: the track is 32 tall and its
segments a quarter of the row, and a larger label is cut there. The
semantics still carry every label whole to a screen reader.
See also:
- GlassTabBar, the same drop on a glass bar.
- GlassSwitch, a two-way choice as a switch.
- GlassDropMotion, how the held drop stretches and squashes.
- Segmented control on the site.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- GlassSegmentedControl
Constructors
-
GlassSegmentedControl({required List<
Widget> segments, required int selectedIndex, required ValueChanged<int> ? onSelected, Color? trackColor, Color? thumbColor, GlassDropMotion? dropMotion, FocusNode? focusNode, bool autofocus = false, Key? key}) -
A control of
segments— at least two — withselectedIndexon the capsule.onSelectednull disables it.const
Properties
- autofocus → bool
-
Whether the control 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
- focusNode → FocusNode?
-
The control's focus. Null makes one the control 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
-
onSelected
→ ValueChanged<
int> ? -
Called with the segment a tap or a drag settles on, when it is not
selectedIndex. Null disables the control; it is then drawn at half
opacity.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
segments
→ List<
Widget> -
One widget per segment — a
Text, anIcon.final - selectedIndex → int
-
The selected segment's index into segments. The capsule slides to it
when it changes, unless a finger is down on the control.
final
- thumbColor → Color?
-
The resting capsule under the selected segment. Null for iOS's: white in
the light appearance, (99, 99, 102) in the dark.
final
- trackColor → Color?
-
The track's fill. Null for iOS's
tertiarySystemFillin the appearance of the label around the control: kGlassSegmentTrack in light, twice its alpha in dark.final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< GlassSegmentedControl> -
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