【Flutter】九、Flutter之滑动条——Slider

一、Slider

Slider是Flutter中的滑动条组件。

1.1 Slider构造器

const Slider({
    Key key,
    @required this.value,
    @required this.onChanged,
    this.onChangeStart,
    this.onChangeEnd,
    this.min = 0.0,
    this.max = 1.0,
    this.divisions,
    this.label,
    this.activeColor,
    this.inactiveColor,
    this.semanticFormatterCallback,
  }) : _sliderType = _SliderType.material,
       assert(value != null),
       assert(min != null),
       assert(max != null),
       assert(min <= max),
       assert(value >= min && value <= max),
       assert(divisions == null || divisions > 0),
       super(key: key);

1.2 Slider属性说明

属性说明
double value当前滑动条的值
ValueChanged onChanged滑动条值改变事件,滑动中一直触发
ValueChanged onChangeStart滑动条开始滑动回调
ValueChanged onChangeEnd滑动条结束滑动回调
double min最小值,默认0.0
double max最大值,默认1.0
int divisions将滑动条几等分
String label拖动滑块时可在滑块上方显示的labeli
Color activeColor滑动条已划过部分及滑块颜色
Color inactiveColor滑动条未划过部分的颜色
SemanticFormatterCallback semanticFormatterCallback用于根据滑块值创建语义值的回调。
例:semanticFormatterCallback: (double newValue) {return '${newValue.round()} dollars}';},

1.3 Slider示例

Row(
	children: <Widget>[
		Text('Slider'),
		Slider(
			value: _sliderValue,
			onChanged: (data){
				print('change:$data');
				setState(() {
					this._sliderValue = data;
				});
			},
			onChangeStart: (data){
				print('start:$data');
			},
			onChangeEnd: (data){
				print('end:$data');
			},
			min: 0.0,
			max: 10.0,
			divisions: 10,
			label: '$_sliderValue',
			activeColor: Colors.green,
			inactiveColor: Colors.grey,
			semanticFormatterCallback: (double newValue) {
				return '${newValue.round()} dollars}';
			},
		)
	],
)

在这里插入图片描述

二、SliderTheme

自定义滑动条样式

2.1 SliderTheme构造器

const SliderTheme({
    Key key,
    @required this.data,
    @required Widget child,
  }) : assert(child != null),
       assert(data != null),
       super(key: key, child: child);
属性说明
SliderThemeData data定义滑动条的相关数据,具体看下面介绍
Widget childSlider控件

三、SliderThemeData

用于自定义滑动条的数据

3.1 SliderThemeData构造器

const SliderThemeData({
    this.trackHeight,
    this.activeTrackColor,
    this.inactiveTrackColor,
    this.disabledActiveTrackColor,
    this.disabledInactiveTrackColor,
    this.activeTickMarkColor,
    this.inactiveTickMarkColor,
    this.disabledActiveTickMarkColor,
    this.disabledInactiveTickMarkColor,
    this.thumbColor,
    this.overlappingShapeStrokeColor,
    this.disabledThumbColor,
    this.overlayColor,
    this.valueIndicatorColor,
    this.overlayShape,
    this.tickMarkShape,
    this.thumbShape,
    this.trackShape,
    this.valueIndicatorShape,
    this.rangeTickMarkShape,
    this.rangeThumbShape,
    this.rangeTrackShape,
    this.rangeValueIndicatorShape,
    this.showValueIndicator,
    this.valueIndicatorTextStyle,
    this.minThumbSeparation,
    this.thumbSelector,
  });

3.2 SliderThemeData属性说明

属性说明
double trackHeight轨道高度
Color activeTrackColor激活部分轨道颜色
Color inactiveTrackColor未激活部分轨道颜色
Color disabledActiveTrackColor滑动条无法使用时被激活轨道的颜色
Color disabledInactiveTrackColor滑动条无法使用时未激活轨道的颜色
Color activeTickMarkColor已激活轨道刻度线的颜色
Color inactiveTickMarkColor未激活轨道刻度线的颜色
Color disabledActiveTickMarkColor滑动条无法使用时已激活轨道刻度线的颜色
Color disabledInactiveTickMarkColor滑动条无法使用时未激活轨道刻度线的颜色
Color thumbColor滑块颜色
Color overlappingShapeStrokeColor
Color disabledThumbColor滑动条不可用时滑块的颜色
Color overlayColor拖动过程中滑块周围绘制的覆盖层的颜色
Color valueIndicatorColorlabel背景色
SliderComponentShape overlayShape拖动过程中滑块周围绘制的覆盖层的大小
RoundSliderOverlayShape(overlayRadius: 20.0)
SliderTickMarkShape tickMarkShape刻度形状
RoundSliderTickMarkShape(tickMarkRadius:2.0)//大于3会消失
SliderComponentShape thumbShape滑块形状
RoundSliderThumbShape(enabledThumbRadius: 12.0,disabledThumbRadius: 3.0)
SliderTrackShape trackShape轨道形状
SliderComponentShape valueIndicatorShape
RangeSliderTickMarkShape rangeTickMarkShape
RangeSliderThumbShape rangeThumbShape
RangeSliderTrackShape rangeTrackShape
RangeSliderValueIndicatorShape rangeValueIndicatorShape
ShowValueIndicator showValueIndicator控制label显示
ShowValueIndicator.onlyForDiscrete:当divisions
TextStyle valueIndicatorTextStylelabel文本样式
double minThumbSeparation
RangeThumbSelector thumbSelector
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MAXLZ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值