Flutter 分段控制组件

Flutter 分段控制组件

CupertinoSegmentedControl

CupertinoSegmentedControl是iOS风格的分段控制组件。

基本使用

在这里插入图片描述

String? _value = "语文";

CupertinoSegmentedControl(
  children: {
    "语文": Container(
      child: const Text("语文"),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    ),
    "数学": Container(
      child: const Text("数学"),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    ),
    "外语": Container(
      child: const Text("外语"),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    ),
  },
  //默认选中
  groupValue: _value,
  onValueChanged: (value) {
    setState(() {
      _value = value as String?;
    });
  },
),

其他使用方法

在这里插入图片描述

String? _value2 = "数学";

CupertinoSegmentedControl(
  children: {
    "语文": Container(
      child: const Text("语文"),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    ),
    "数学": Container(
      child: const Text("数学"),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    ),
    "外语": Container(
      child: const Text("外语"),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    ),
  },
  //选中(选中的背景颜色,未选中的文字颜色)
  selectedColor: Colors.red,
  //未选中(未选中的背景颜色,选中的文字颜色)
  unselectedColor: Colors.white,
  //按下
  pressedColor: Colors.red[50],
  //边框颜色
  borderColor: Colors.black,
  groupValue: _value2,
  onValueChanged: (value) {
    setState(() {
      _value2 = value as String?;
    });
  },
),

CupertinoSlidingSegmentedControl

iOS风格的分段滑动组件。

在这里插入图片描述

String? _value3 = "语文";

CupertinoSlidingSegmentedControl(
  children: {
    '语文': Container(
      child: const Text('语文'),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    ),
    '数学': Container(
      child: const Text('数学'),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    ),
    '体育': Container(
      child: const Text('体育'),
      padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
    )
  },
  groupValue: _value3,
  onValueChanged: (value) {
    setState(() {
      _value3 = value as String?;
    });
  },
),
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值