boeledi / RangeSlider

RangeSlider Widget for Flutter
Other
374 stars 66 forks source link

How do I maintain state? #15

Closed jordan-clark closed 5 years ago

jordan-clark commented 5 years ago

How do I get the slider to maintain state? I am using the slider in a SimpleDialog and want the min and max values updated when a user opens/closes the dialog.

I attempted to create a double variable for both min and max, then update those variables after the user has closed the dialog using shared_preferences. However, after the slider has the min and max variables assigned, if I drag the slider I immediately get the exception:

image

Code:

double rentMin = 500.0;
double rentMax = 3000.0;

RangeSlider(
  min: rentMin,
  max: rentMax,
  lowerValue: _lowerValue,
  upperValue: _upperValue,
  showValueIndicator: false,
  valueIndicatorMaxDecimals: 2,
  onChanged: (double newLowerValue, double newUpperValue) {
    setState(() {
      _lowerValue = newLowerValue;
      _upperValue = newUpperValue;
    });
  },
  onChangeStart:(double startLowerValue, double startUpperValue) {
    print('Started with values: $startLowerValue and $startUpperValue');
  },
  onChangeEnd: (double newLowerValue, double newUpperValue) {
    print('Ended with values: $newLowerValue and $newUpperValue');
  },
),

Upon dialog close I have a method that assigns the value of _lowerValue to rentMin and _upperValue to rentMax .

jordan-clark commented 5 years ago

Figured it out - had the variables being declared in wrong location.