I use the BottomNavigationBar
that switches between the display of 5 different pages. Changing the pages is done with the help of PageController
together with the PageView
widget.
Within the pages, there are timers that run when entering and exiting the page and pull data from the server every X time by using Timer.periodic
.
Because of the use of PageView
, the pages are built at the same time and all the timers are running, how can the timers be canceled when moving from page to page through each page by itself?
you could listen to the PageController
and stop the timer. Like this
pageController.addListener(() {
if(controller.page == 1){
timer.cancel();
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.