Search code examples
flutterdartrangeslider

How to prevent user from being able to slide left thumb in Flutter RangeSilder


This is my range slider widget implementation, I want to prevent the user from being able to slide the left thumb slider

  RangeSlider(
                          divisions: 5,
                          activeColor: Colors.red[700],
                          inactiveColor: Colors.grey,
                          min: 1.0,
                          max: 10.0,
                          values: values,
                          labels: labels,
                          onChanged: (value) {
                            state(
                              () {
                                values = value;
                                labels = RangeLabels(
                                  "${value.start.toInt().toString()}km",
                                  "${value.end.toInt().toString()}km",
                                );
                              },
                            );
                          },
                        ),

Solution

  • Add if (values.start != value.start) return; inside your onChanged, this will prevent updating values which prevent updating the RangeSlider