You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何以编程方式更新CupertinoSlidingSegmentedControl的值?

CupertinoSlidingSegmentedControl 编程式更新选中值的问题

CupertinoSlidingSegmentedControl 并未提供编程式更新选中值的官方方法。目前唯一的变通方案是更新组件的Key(例如使用ValueKey),但这种操作会导致滑动过渡效果被禁用,体验并不理想。

组件代码示例:

CupertinoSlidingSegmentedControl(
    padding: EdgeInsets.zero,
    thumbColor: ColorAssets.green,
    groupValue: selected,
    onValueChanged: (value) {
     
    },
    children: widget.children.map(
      (key, value) => MapEntry(
        key,
         Container(
            height: constraints.maxHeight,
            alignment: Alignment.center,
            padding: const EdgeInsets.only(bottom: 2),
            child: Text(
              value,
            ),
          )
      ),
    ),
  )

内容的提问来源于stack exchange,提问作者Abrar Malekji

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 08:25:57