Is it possible to set label color different to active color? I tried a lot of options (see below) but nothing works.
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
Answers
you can give label color to slider by using SliderTheme like this
Certainly! This code snippet demonstrates customizing the label color separately from the slider’s active color using a Tooltip widget. It positions the label adjacent to the Slider, displaying the value with a red-colored Text style. Adjust the color or any other text style properties as needed to fit your design preferences.