In my app, I have a PageView
and a Slider
. When I scroll the PageView
, I expect the Slider
to change its value, and when I slide the Slider
I expect the page of the PageView
to change as well. For this, I have a state to be the value
of the Slider
, and in onChanged
I will have the change its value, and in onChangeEnd
will animate the PageView
to the desire position:
Slider(
value: _sliderValue,
onChanged: (val) {
setState(() {
_sliderValue = val;
});
},
onChangeEnd: (val) {
_controller.animateToPage(val.toInt(),
duration: Duration(milliseconds: 300), curve: Curves.ease);
},
max: (pages.length - 1).toDouble())
And in PageView
, I have to update the _sliderValue
as well, so it works when I scroll the PageView
:
PageView.builder(
onPageChanged: (page) {
setState(() {
_sliderValue = page.toDouble();
});
},
)
Problem is, I now have 2 places that I change the _sliderValue
- one in onChanged
for the Slider
to be responsive, one in onPageChanged
to work with scrolling. This makes the slider jarring when I press repeatedly on it.
Is there any way to solve this issue?