Flutter Cupertino风格组件(CupertinoSlider)

CupertinoSlider滑动按钮,效果如图所示:
Flutter Cupertino风格组件(CupertinoSlider)

CupertinoSlider主要属性参如表所示:
Flutter Cupertino风格组件(CupertinoSlider)

设置CupertinoSlider的最小值1,最大值10,分割5份,划过区域颜色为红色,代码如下:

class CupertinoSliderDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _CupertinoSliderDemo();
}

class _CupertinoSliderDemo extends State<CupertinoSliderDemo> {
  double _value = 1.0;

  @override
  Widget build(BuildContext context) {
return Center(
  child: CupertinoSlider(
value: _value,
onChanged: (double v) {
  setState(() {
    print('$v');
    _value = v;
  });
},
min: 1.0,
max: 10.0,
divisions: 5,
activeColor: Colors.red,
  ),
);
  }
}

CupertinoSlider本身不支持滑动,必须在onChange回调中改变value的值才可以,setState方法会立刻刷新屏幕,改变其状态。

酷客网相关文章:

赞(0)

评论 抢沙发

评论前必须登录!