CupertinoSlidingSegmentedControl<T> class

An iOS 13 style segmented control.

Displays the widgets provided in the Map of children in a horizontal list. It allows the user to select between a number of mutually exclusive options, by tapping or dragging within the segmented control.

A segmented control can feature any Widget as one of the values in its Map of children. The type T is the type of the Map keys used to identify each widget and determine which widget is selected. As required by the Map class, keys must be of consistent types and must be comparable. The children argument must be an ordered Map such as a LinkedHashMap, the ordering of the keys will determine the order of the widgets in the segmented control.

The widget calls the onValueChanged callback when a valid user gesture completes on an unselected segment. The map key associated with the newly selected widget is returned in the onValueChanged callback. Typically, widgets that use a segmented control will listen for the onValueChanged callback and rebuild the segmented control with a new groupValue to update which option is currently selected.

The children will be displayed in the order of the keys in the Map, along the current TextDirection. Each child widget will have the same size. The height of the segmented control is determined by the height of the tallest child widget. The width of each child will be the intrinsic width of the widest child, or the available horizontal space divided by the number of children, which ever is smaller.

A segmented control may optionally be created with custom colors. The thumbColor, backgroundColor arguments can be used to override the segmented control's colors from its defaults.

This example shows a CupertinoSlidingSegmentedControl with an enum type.

The callback provided to onValueChanged should update the state of the parent StatefulWidget using the State.setState method, so that the parent gets rebuilt; for example:


To create a local project with this code sample, run:
flutter create --sample=cupertino.CupertinoSlidingSegmentedControl.1 mysample

See also:



CupertinoSlidingSegmentedControl({Key? key, required Map<T, Widget> children, required ValueChanged<T?> onValueChanged, T? groupValue, Color thumbColor = _kThumbColor, EdgeInsetsGeometry padding = _kHorizontalItemPadding, Color backgroundColor = CupertinoColors.tertiarySystemFill})
Creates an iOS-style segmented control bar.


backgroundColor Color
The color used to paint the rounded rect behind the children and the separators.
children Map<T, Widget>
The identifying keys and corresponding widget values in the segmented control.
groupValue → T?
The identifier of the widget that is currently selected.
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
onValueChanged ValueChanged<T?>
The callback that is called when a new option is tapped.
padding EdgeInsetsGeometry
The amount of space by which to inset the children.
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
thumbColor Color
The color used to paint the interior of the thumb that appears behind the currently selected item.


createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
createState() State<CupertinoSlidingSegmentedControl<T>>
Creates the mutable state for this widget at a given location in the tree.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
toStringShort() String
A short, textual description of this widget.


operator ==(Object other) bool
The equality operator.