title: 'CupertinoSegmentedControl' description: '' type: widget

CupertinoSegmentedControl

iOS样式的分段控制组件,用法如下:

CupertinoSegmentedControl(
  children: {
    '语文':Container(child: Text('语文'), padding: EdgeInsets.symmetric(vertical: 5,horizontal: 10),),
    '数学':Container(child: Text('数学'), padding: EdgeInsets.symmetric(vertical: 5,horizontal: 10),),
    '体育':Container(child: Text('体育'), padding: EdgeInsets.symmetric(vertical: 5,horizontal: 10),)
  },
  onValueChanged: (value){
    print(value);
  },
)

image-20200526181817167

groupValue表示当前选中的值,

String _value = '语文';

@override
Widget build(BuildContext context) {
  return Center(
    child: CupertinoSegmentedControl(
      children: {
        '语文':Container(child: Text('语文'), padding: EdgeInsets.symmetric(vertical: 5,horizontal: 10),),
        '数学':Container(child: Text('数学'), padding: EdgeInsets.symmetric(vertical: 5,horizontal: 10),),
        '体育':Container(child: Text('体育'), padding: EdgeInsets.symmetric(vertical: 5,horizontal: 10),)
      },
      groupValue: _value,
      onValueChanged: (value){
        setState(() {
          _value = value;
        });
      },
    ),
  );
}

CupertinoSegmentedControl

unselectedColor表示未选中的背景颜色和选中的字体颜色:

CupertinoSegmentedControl(
  unselectedColor: Colors.yellow,
  ...
)

image-20200526182812968

selectedColor表示选中的背景颜色和未选中的字体颜色:

CupertinoSegmentedControl(
  selectedColor: Colors.red,
  ...
)

image-20200526182915710

pressedColor表示按住时的颜色:

CupertinoSegmentedControl(
  pressedColor: Colors.red,
  ...
) 

image-20200526183107025

borderColor表示边框颜色:

CupertinoSegmentedControl(
  borderColor: Colors.red,
  ...
) 

image-20200526183157813