颤动的屏幕更改回调 [英] Flutter screen change callback

查看:81
本文介绍了颤动的屏幕更改回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当屏幕更改时,我希望获得回调,因此我可以停止在该特定屏幕上运行的重复请求.仅在使用Navigator.pop时才调用"dispose",而在调用Navigator.push时不调用.有没有一种方法可以检测到屏幕已更改并且目前没有显示?

I want to get a callback when the screen is changed, so I can stop my recurring request that runs on that specific screen. "dispose" is only called when Navigator.pop is used, but not when Navigator.push is called. Is there a way to detect that the screen is changed and not being shown at the moment?

推荐答案

在MaterialApp或WidgetsApp上注册RouteObserver,并使有状态的小部件成为RouteAware.此处的示例代码: RouteObserver

Register a RouteObserver on your MaterialApp or WidgetsApp and make your stateful widget a RouteAware. Sample code here: RouteObserver

这篇关于颤动的屏幕更改回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆