unselectedColor property

Color? unselectedColor
final

The callback that is called when a new option is tapped.

This attribute must not be null.

The segmented control passes the newly selected widget's associated key to the callback but does not actually change state until the parent widget rebuilds the segmented control with the new groupValue.

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:

{@tool snippet}

class MultipleSegmentedControlExample extends StatefulWidget {
  const SegmentedControlExample({Key? key}) : super(key: key);

  @override
  State createState() => MultipleSegmentedControlExampleState();
}

class MultipleSegmentedControlExampleState extends State<MultipleSegmentedControlExample> {
  final _children = const <Widget>[
    Text('Child 1'),
    Text('Child 2'),
  ];
  final _isSelected = [false, false];

  @override
  Widget build(BuildContext context) {
    return CupertinoMultipleSegmentedControl(
      children: _children,
      isSelected: _isSelected,
      onPressed: (int index) {
        setState(() {
          _isSelected[index] = !_isSelected[index];
        });
      },
    );
  }
}

{@end-tool} The color used to fill the backgrounds of unselected widgets and as the text color of the selected widget.

Defaults to CupertinoTheme's primaryContrastingColor if null.

Implementation

/// The color used to fill the backgrounds of unselected widgets and as the
/// text color of the selected widget.
///
/// Defaults to [CupertinoTheme]'s `primaryContrastingColor` if null.
final Color? unselectedColor;