Flutter slider overlay color - flutter

I have changed the color of the overlay but it still does not take effect as it maintains the color of the thumbShape instead.
SliderTheme(
data: SliderTheme.of(context).copyWith(
thumbColor: Color(0xFFEB1555),
activeTrackColor: Colors.white,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 15.0),
overlayShape: RoundSliderThumbShape(enabledThumbRadius: 25.0),
overlayColor: Color(0x29EB1555),
),
child: Slider(
value: height.toDouble(),
min: 122.0,
max: 220.0,
inactiveColor: Color(0xFF8D8E98),
onChanged: (double newValue) {
setState(() {
height = newValue.round();
});
},
),
),

I removed the overlayShape.
I think it was overriding the color I wanted to use.

You can use the inactive and active track color in your theme to avoid this problem.
SliderTheme(
data: SliderThemeData(
thumbShape: RoundSliderThumbShape(
enabledThumbRadius: 15,
),
overlayColor: Color(0x29eb1555),
activeTrackColor: Colors.white,
inactiveTrackColor: Color(0xff8d8e98),
thumbColor: Color(0xffeb1555),
),
child: Slider(
value: height.toDouble(),
min: 120,
max: 220,
onChanged: (value) {
setState(() {
height = value.round();
});
},
),
),

You used RoundSliderThumbShape for both thumbShape and overlayShape. Instead, use RoundSliderOverlayShape for overlayShape property, and you are good to go.
data: SliderTheme.of(context).copyWith(
thumbColor: Color(0xFFEB1555),
activeTrackColor: Colors.white,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 15.0),
overlayShape: RoundSliderOverlayShape(overlayRadius: 25.0), // Change in here
overlayColor: Color(0x29EB1555),
),

Related

Flutter : Slider custom Tooltip

I want to make the custom tooltip with a background shadow for Slider in my app. Here is my code for the current slider.
SliderTheme(
data: SliderThemeData(
activeTrackColor: AppColor.royalGreen,
inactiveTrackColor: AppColor.black12,
thumbColor: AppColor.royalGreen,
thumbShape: CircleSliderThumbShape(),
showValueIndicator: ShowValueIndicator.always,
valueIndicatorColor: AppColor.white,
valueIndicatorTextStyle: TextStyles.sliderTooltipText,
// overlayShape: SliderComponentShape.noOverlay,
// overlayColor: AppColor.behan24
),
child: Slider(
value: _currentSliderValue,
onChanged: (double value) {
setState(() {
_currentSliderValue = value;
});
},
label: "${_currentSliderValue.toString().split('.')[0] + 'L'}",
min: 5,
max: 50,
),
),
This is what I want to achieve.
What I have achieved so far.
Any help will be appreciable. Thanks
I recommend using the library flutter_xlider
With this, you can customize using the Tooltip and add a shadow to create the effect of elevation.
FlutterSlider(
values: [300],
max: 500,
min: 0,
onDragging: (handlerIndex, lowerValue, upperValue) {
_lowerValue = lowerValue;
_upperValue = upperValue;
setState(() {});
},
tooltip: FlutterSliderTooltip(
textStyle: TextStyle(fontSize: 17, color: Colors.black),
boxStyle: FlutterSliderTooltipBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
)),
),
This is what you will achieve:

Why parent class is accepting color from child?

I'm working on Slider, I want to change the thumb color, but this is not working. thumbColor accepts color from Child:Slider activeColor.
SliderTheme(
data:SliderTheme.of(context).copyWith(
// thumbShape: RoundSliderThumbShape(enabledThumbRadius: 19.0),
// overlayColor: Colors.grey,
thumbColor: Colors.white,
),
child: Slider(
inactiveColor: Colors.transparent,
min: 0,
activeColor: Color(0xffF3C961),
value: value.toDouble(),
max: MediaQuery.of(context).size.height,
onChanged: (changedValue){
setState(() {
value = changedValue.toInt();
});
},
),
),[![You can check color of thumb shape][1]][1]

How to set slider overlay color?

I'm trying to set slider overlay color but it seems that it only works if I comment out overlayShape: RoundSliderThumbShape(enabledThumbRadius: 30), how to I set both?
P.S. Relevant part code is marked with comments
SliderTheme(
data: SliderTheme.of(context).copyWith(
activeTrackColor: kDefaultColor,
inactiveTrackColor: kDefaultColor,
thumbColor: kButtonColor,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 15),
overlayShape: RoundSliderThumbShape(enabledThumbRadius: 30), //focus here
overlayColor: Colors.red //focus here
),
child: Slider(
value: sliderValue.toDouble(),
max: 220,
min: 110,
onChanged: (double value) {
setState(() {
sliderValue = value.round();
});
},
),
),
You should use RoundSliderOverlayShape for overlayShape.
overlayShape: RoundSliderOverlayShape(overlayRadius: 30),

How to change color of divisions in Slider flutter

Hello i have slider with divisions. What is the theme property for changing divisions color so they are not visible?
Please see this example and let me know if you need any further help :
SliderTheme(
data: SliderTheme.of(context).copyWith(
trackHeight: 10.0,
minThumbSeparation: 2,
thumbColor: Colors.white,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 12.0),
overlayColor:Colors.deepPurple,
inactiveTickMarkColor: Colors.amber,
inactiveTrackColor: Colors.green,
),
child: Slider(
min: 1,
max: 100,
value: 45,
divisions: 2,
onChanged: (newValue) {
// set the new value here
setState(() {
progress= newValue;
});
},
),
)
Let's demonstrate some params:
The Main Param for changing the color of the divisions is inactiveTickMarkColor param in SliderTheme object which is amber in our case.
Feel free to change it as you want.
The inactiveTrackColor param is the color of the slider when the area is not in the active rang.
The overlayColor param is the color of the widget that appears when you press or focus on the selector widget.
you can wrap you slider with SliderTheme widget and then adding SliderThemeData to it, inside SliderThemeData ,
where TickMark defines division,
you would find properties for changing TickMark color,
here is an example
data: SliderThemeData(
activeTickMarkColor: Colors.transparent,
inactiveTickMarkColor: Colors.transparent,
thumbColor: ColorAssets.themeColorMagenta,
activeTrackColor: ColorAssets.themeColorMagenta,
inactiveTrackColor: Colors.white,
),
child: Slider(
value: textSliderValue,
min: 0,
max: 20,
divisions: 20,
),
)
You can change ColorScheme's primary color to change slider's color, but it requires to assign value of all colors.
colorScheme: ColorScheme(
primary: Colors.amber,
primaryVariant: Colors.amber,
secondary: Colors.amber,
secondaryVariant: Colors.amber,
surface: Colors.amber,
background: Colors.amber,
error: Colors.amber,
onPrimary: Colors.amber,
onSecondary: Colors.amber,
onSurface: Colors.amber,
onBackground: Colors.amber,
onError: Colors.amber,
brightness: Brightness.light),

How to hide thumb on flutter Slider Widget?

I have to hide the thumb on Slider widget. I set thumb colour to transparent with SliderTheme widget. It does not work. How to hide thumb?
I set thumb colour to transparent.
Center(
child: SliderTheme(
child: Slider(
value: 50,
max: 100,
min: 0,
activeColor: Colors.black,
inactiveColor: Colors.grey,
onChanged: (double value) {},
),
data: SliderTheme.of(context).copyWith(
trackHeight: 28,
thumbColor: Colors.transparent,
thumbShape: null),
),
)
I expect the slider widget without thumb.
Bit of a workaround but you can set the thumbShape to have a radius of 0:
Center(
child: SliderTheme(
child: Slider(
value: 50,
max: 100,
min: 0,
activeColor: Colors.black,
inactiveColor: Colors.grey,
onChanged: (double value) {},
),
data: SliderTheme.of(context).copyWith(
trackHeight: 28,
thumbColor: Colors.transparent,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 0.0)),
),
),
Not a workaround. The correct way to do it.
Set the thumbShape to SliderComponentShape.noThumb
i.e.
SliderTheme.of(context).copyWith(
trackHeight: 28,
thumbShape: SliderComponentShape.noThumb,