To update a RangeSlider with Flutter's ValueListenableBuilder, you can follow these steps:
ValueNotifier<double> _minValue = ValueNotifier<double>(0.0);
ValueNotifier<double>_maxValue = ValueNotifier<double>(100.0);
RangeSlider(
min: 0.0,
max: 100.0,
values: RangeValues(_minValue.value, _maxValue.value),
onChanged: (RangeValues values) {
_minValue.value = values.start;
_maxValue.value = values.end;
},
),
ValueListenableBuilder(
valueListenable: _minValue,
builder: (BuildContext context, double minValue, Widget child) {
return RangeSlider(
min: 0.0,
max: 100.0,
values: RangeValues(minValue, _maxValue.value),
onChanged: (RangeValues values) {
_minValue.value = values.start;
_maxValue.value = values.end;
},
);
},
),
ValueListenableBuilder(
valueListenable: _maxValue,
builder: (BuildContext context, double maxValue, Widget child) {
return RangeSlider(
min: 0.0,
max: 100.0,
values: RangeValues(_minValue.value, maxValue),
onChanged: (RangeValues values) {
_minValue.value = values.start;
_maxValue.value = values.end;
},
);
},
),
With these steps, the RangeSlider will be updated whenever the values of the corresponding ValueNotifier objects change.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-08 12:23:08 +0000
Seen: 20 times
Last updated: Jun 08 '23
How can one ensure that sub-classes have uniform method parameters in TypeScript?
How can the calculation of matrix determinant be performed using CUDA?
How can code repetition be prevented when using (box)plot functions?
When I attempt to generate a database, why does the azure-cosmos-emulator become unresponsive?
What steps can I take to prevent my webpage from slowing down when all parts of a div are displayed?