繁体   English   中英

Flutter 生命周期与 .autoDispose 修饰符一起使用

[英]Flutter lifecycle used with .autoDispose modifier

我一直试图了解 Riverpod 是如何工作的,并且想知道在更改 Flutter 中的路线时,它如何知道何时使用 .autoDispose 修饰符销毁提供者的 state。它是否以某种方式订阅了导航器更改?

文档 state:

A common use case is to destroy the state of a provider when it is no-longer used.

There are multiple reasons for doing so, such as:

- When using Firebase, to close the connection and avoid unnecessary cost.
- ***To reset the state when the user leaves a screen and re-enters it.****

“autoDispose”逻辑不依赖于特定于 Flutter 的逻辑。
相反,它完全依赖于当前是否正在收听提供者。

弹出路由时,关联的小部件将被销毁。 这会导致该路由中的ConsumerWidget停止收听其“已监视”提供者。

然后,如果提供者现在没有更多的侦听器,它就会被处理掉。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM