Home > Enterprise >  Deactivate a region of range slider
Deactivate a region of range slider

Time:07-06

I'd like to show on my range slider 0 to 300 but only allow the user to select from 80 to 300


RangeSlider(
  min: 0.0,
  max: 300.0,
  divisions: 10,
  labels: RangeLabels(
    _startValue.round().toString(),
    _endValue.round().toString(),
  ),
  values: RangeValues(_startValue, _endValue),
  onChanged: (values) {
    setState(() {
      _startValue = values.start;
      _endValue = values.end;
    });
  },
)

CodePudding user response:

You can check start value on onChanged and stop user from going <80.

onChanged: (values) {
  if (values.start < 80) return;
  setState(() {
    _startValue = values.start;
    _endValue = values.end;
  });
},

CodePudding user response:

You can just import import 'dart:math'; and then use min and max functions to limit the values:

onChanged: (values) {
  setState(() {
    _startValue = max(values.start, 80);
    _endValue = min(values.end, 250); // If you also want to limit the upper value
  });
},

CodePudding user response:

Actually, you could use if..else to make it happen.

onChanged: (value) {
                if((value)<=80){
                  setState(() {
                    _startValue = 80;
                  });
                }
              },
  • Related