[英]Stop timer when changing page with page view and bottom navigation
I use the BottomNavigationBar
that switches between the display of 5 different pages.我使用在 5 个不同页面的显示之间切换的BottomNavigationBar
。 Changing the pages is done with the help of PageController
together with the PageView
widget.更改页面是在PageController
和PageView
小部件的帮助下完成的。
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
.在页面中,有计时器在进入和退出页面时运行,并使用Timer.periodic
每 X 次从服务器拉取数据。
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?因为使用PageView
,页面是同时构建的,所有的定时器都在运行,如何在页面移动时通过自己的页面移动到页面时取消定时器?
you could listen to the PageController
and stop the timer.您可以收听PageController
并停止计时器。 Like this像这样
pageController.addListener(() {
if(controller.page == 1){
timer.cancel();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.