是否可以将标签颜色设置为与活动颜色不同?我尝试了很多选项(见下文),但都不起作用。
import 'package:flutter/material.dart';
void main() {
var themeData = ThemeData(
useMaterial3: true,
);
runApp(MaterialApp(
theme: themeData.copyWith(
sliderTheme: themeData.sliderTheme.copyWith(
valueIndicatorColor: themeData.primaryColor,
disabledActiveTickMarkColor: themeData.primaryColor,
disabledActiveTrackColor: themeData.primaryColor,
disabledInactiveTickMarkColor: themeData.primaryColor,
disabledInactiveTrackColor: themeData.primaryColor,
disabledSecondaryActiveTrackColor: themeData.primaryColor,
activeTickMarkColor: themeData.primaryColor,
activeTrackColor: themeData.primaryColor,
secondaryActiveTrackColor: themeData.primaryColor,
inactiveTickMarkColor: themeData.primaryColor,
inactiveTrackColor: themeData.primaryColor,
)),
home: const MyHomePage(),
));
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double sliderValue = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Slider(
value: sliderValue,
max: 23,
divisions: 23,
label: "$sliderValue",
inactiveColor: Theme.of(context).primaryColor,
activeColor: Theme.of(context).disabledColor,
thumbColor: Theme.of(context).primaryColor,
onChanged: (double value) {
setState(() {
sliderValue = value;
});
},
),
);
}
}
字符串
2条答案
按热度按时间41zrol4v1#
你可以通过像这样使用SliderTheme给滑块给予标签颜色
字符串
06odsfpq2#
当然可以!此代码片段演示了使用工具提示小部件单独自定义标签颜色和滑块的活动颜色。它将标签放置在滑块附近,以红色文本样式显示值。根据需要调整颜色或任何其他文本样式属性以适合您的设计首选项。
字符串