I have a scroll listener for hiding and showing the bottom navigation bar, It works perfectly but I discover it will fire the function almost 50 times and more when it meets the condition if I scroll too fast. Which means it will rebuild the widget so many times right? How can I prevent this from happening.
updateBottomBar
is a callback function to setstate the parent widget.
bottomBarVisible
is the variable to show and hide the bottom nav bar.
@override
void initState() {
scrollController.addListener(() {
//listener
if (scrollController.position.userScrollDirection ==
ScrollDirection.reverse &&
widget.bottomBarVisible == true) {
print("it is hide");
widget.updateBottomBar(false);
} else if (scrollController.position.userScrollDirection ==
ScrollDirection.forward &&
widget.bottomBarVisible == false) {
print("it is show");
widget.updateBottomBar(true);
}
});