Segmented<T> class
A single-select control laid out as a strip of segments, with a thumb that slides to the chosen one — for switching between a few mutually exclusive options in place.
Segmented<String>(
value: _view,
options: const [
SegmentedOption(value: 'list', label: 'List'),
SegmentedOption(value: 'grid', label: 'Grid'),
],
onChanged: (v) => setState(() => _view = v),
)
Segments size to their content, so long labels are never clipped. Set block to stretch them to fill the width equally, or direction to stack them vertically. For more than a handful of options, or navigation between views, prefer tabs.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- Segmented
Constructors
-
Segmented({Key? key, required T value, required List<
SegmentedOption< options, ValueChanged<T> >T> ? onChanged, ControlSize? size, Axis? direction, bool block = false, bool? scrollButtons, SegmentedArrowBuilder? arrowBuilder, SegmentedController? controller, bool? disabled, bool readOnly = false, Color? trackColor, Color? thumbColor, FocusNode? focusNode, bool autofocus = false, SegmentedToken? token}) -
Creates a Segmented.
const
Properties
- arrowBuilder → SegmentedArrowBuilder?
-
Builds the arrows yourself. Null draws the kit's.
final
- autofocus → bool
-
Whether the run takes focus as soon as it is built.
final
- block → bool
-
Stretch the segments to fill the available space equally.
final
- controller → SegmentedController?
-
Drives the run's scrolling from outside the build.
final
- direction → Axis?
-
Whether the segments run in a row or a column.
final
- disabled → bool?
-
Greys the whole control out and blocks selection.
final
- focusNode → FocusNode?
-
A focus node of your own, for a run 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
-
onChanged
→ ValueChanged<
T> ? -
Called with the new value when a segment is chosen. Null disables the
whole control.
final
-
options
→ List<
SegmentedOption< T> > -
The segments, in order.
final
- readOnly → bool
-
Shows which is chosen without letting anyone choose another.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollButtons → bool?
-
Whether a run too big for its space offers arrows to step through it.
final
- size → ControlSize?
-
Which height preset to use.
final
- thumbColor → Color?
-
Overrides the sliding thumb's colour.
final
- token → SegmentedToken?
-
Per-instance token overrides.
final
- trackColor → Color?
-
Overrides the track (background) colour.
final
- value → T
-
The selected value. Must match one option's value.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Segmented< T> > -
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