how to add discrete points to slider without using divisions in flutter - flutter

i want to add points to the slider but without using divisions
SliderTheme(
data: SliderThemeData(
trackHeight: 1,
),
child: RangeSlider(
min: 0.0,
max: 4.0,
onChanged: _onChange,
values: state.value,
onChangeEnd: _onChangeEnd,
inactiveColor: Colors.grey,
activeColor: Theme.of(state.context).accentColor,
),
), `

Related

Flutter slider overlay color

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),
),

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 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,