[英]Changing thumb color of slider in flutter
I am trying to change the thumb color of my slider.我正在尝试更改滑块的拇指颜色。
Here is my code:这是我的代码:
SliderTheme(
data: SliderThemeData(
thumbColor: Colors.pink,
),
child: Slider(
value: height.toDouble(),
min: 120,
max: 220,
onChanged: (double newValue){
setState(() {
height = newValue.toInt();
});
},
inactiveColor: Color(0xff8d8e98),
activeColor: Colors.white,
),
)
However if I remove activeColor: Colors.white
property from above code then I am getting the desired thumb color.但是,如果我从上面的代码中删除
activeColor: Colors.white
属性,那么我将获得所需的拇指颜色。
However if I add activeColor
parameter back then even thumb color changes.但是,如果我添加
activeColor
参数,那么即使拇指颜色也会改变。
How to get thumb color as pink and active color as white?如何使拇指颜色为粉红色,活动颜色为白色?
Here is my required output:这是我需要的输出:
Try using activeTrackColor:
rather than activeColor:
, eg:尝试使用
activeTrackColor:
而不是activeColor:
,例如:
data: SliderThemeData(
thumbColor: Colors.pink,
activeTrackColor: Colors.white,
inactiveColor: Color(0xff8d8e98),
),
You can use overlayColor
for shade around thumb and activeTrackColor
properties of SliderThemeData.您可以将
overlayColor
用于滑块周围的阴影和SliderThemeData 的activeTrackColor
属性。
SliderTheme(
data: SliderThemeData(
thumbColor: Colors.pink,
overlayColor:Colors.pink[50],
activeTrackColor: Colors.white,
),
child: Slider(
value: sliderValue.toDouble(),
max: 100.0,
min: 0.0,
inactiveColor: Colors.grey,
onChanged: (double newValue) {
setState(() {
sliderValue = newValue;
});
},
),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.