Ali-Azmoud / flutter_xlider

A material design slider and range slider with rtl support and lots of options and customization for flutter
https://pub.dartlang.org/packages/flutter_xlider
MIT License
519 stars 184 forks source link

On drag one value keeps falsely showing up as selected #100

Open ehaberkorn opened 3 years ago

ehaberkorn commented 3 years ago

If I set the percent inside on FlutterSliderFixedValue to 3 and the value to 6, the 6 keeps showing up as selected even if it is not. When I leave the 3 out as percent everything works as expected. Please refer to the code snippet below.

FlutterSlider(
                              trackBar: FlutterSliderTrackBar(
                                activeTrackBar: BoxDecoration(
                                    color: AppColors.DARK_BLUE_FF085651),
                              ),
                              tooltip: null,
                              handler: FlutterSliderHandler(
                                  child: Container(),
                                  decoration: BoxDecoration(
                                      boxShadow: [
                                        BoxShadow(
                                            color: Colors.black26,
                                            blurRadius: 2,
                                            spreadRadius: 0.2,
                                            offset: Offset(0, 1))
                                      ],
                                      color: Colors.white,
                                      shape: BoxShape.circle)),
                              values: [
                                3,
                                4,
                                5,
                                6,
                                7.5,
                                10,
                                15,
                                20,
                                30,
                                40,
                                50,
                                75,
                                100,
                                150,
                                200
                              ],
                              min: 3,
                              max: 200,
                              onDragging: (index, newValue, upperValue) {
                                setState(() {
                                  _sliderValue = newValue.toDouble();
                                });
                              },
                              jump: true,
                              fixedValues: [
                                FlutterSliderFixedValue(percent: 0, value: 3),
                                FlutterSliderFixedValue(percent: 1, value: 4),
                                FlutterSliderFixedValue(percent: 2, value: 5),
                                FlutterSliderFixedValue(percent: 3, value: 6),    //this is causing the behavior
                                FlutterSliderFixedValue(percent: 4, value: 7.5),
                                FlutterSliderFixedValue(percent: 5, value: 10),
                                FlutterSliderFixedValue(percent: 7, value: 15),
                                FlutterSliderFixedValue(percent: 10, value: 20),
                                FlutterSliderFixedValue(percent: 15, value: 30),
                                FlutterSliderFixedValue(percent: 20, value: 40),
                                FlutterSliderFixedValue(percent: 25, value: 50),
                                FlutterSliderFixedValue(percent: 37, value: 75),
                                FlutterSliderFixedValue(
                                    percent: 50, value: 100),
                                FlutterSliderFixedValue(
                                    percent: 75, value: 150),
                                FlutterSliderFixedValue(
                                    percent: 100, value: 200)
                              ],
                              step: FlutterSliderStep(
                                step: 1, // default
                                isPercentRange: false,
                              ),
                            )
Ali-Azmoud commented 3 years ago

Hello. sorry for my late response. This is a bug and is fixed in the upcoming version.
The cause of the bug is setState which sets state to initial value. and your initial value in values array is 3, so the fixed value for 3 is 6
Also the way you use values is not correct. values array only accepts two number, one for lower and one for upper values.
the next version will be ready in the next couple days

ehaberkorn commented 3 years ago

Hi, thanks for the info. I have fixed my values to only two. Also I found out that, if any of the other widgets I use in my view calls setState() the slider gets reset. I guess that this will be fixed with the next version because it is related to this issue.

ehaberkorn commented 3 years ago

@Ali-Azmoud is there any progress? Sorry for the pressure, but I need this urgently...

arslan9380 commented 3 years ago

still not fixed?