根据 Flutter api 使用 valueIndicatorColor 这是 SliderThemeData 的属性 正如这里提到的滑块类 https://api.flutter.dev/flutter/material/Slider-class.html和这里滑块主题数据 https://api.flutter.dev/flutter/material/SliderThemeData-class.html
简单演示:
设置局部变量:
double feet = 0;
String heightInFeet = "null";
int height = 180;
您的自定义滑块解决方案来了
SliderTheme(
data: SliderTheme.of(context).copyWith(
valueIndicatorColor: Colors.blue, // This is what you are asking for
inactiveTrackColor: Color(0xFF8D8E98), // Custom Gray Color
activeTrackColor: Colors.white,
thumbColor: Colors.red,
overlayColor: Color(0x29EB1555), // Custom Thumb overlay Color
thumbShape:
RoundSliderThumbShape(enabledThumbRadius: 12.0),
overlayShape:
RoundSliderOverlayShape(overlayRadius: 20.0),
),
child: Slider(
value: height.toDouble(),
onChanged: (double newValue) {
setState(() {
height = newValue.toInt();
feet = (height / 30.48);
heightInFeet = feet.toStringAsFixed(2) + " feet";
});
},
divisions: 220,
label: heightInFeet,
min: 90.0,
max: 305.0,
),
)
如果您想更改文本颜色文本字体等,请使用
valueIndicatorTextStyle: TextStyle(
color: Colors.amber, letterSpacing: 2.0)
在 SliderThemeData 中