简体   繁体   English

riverpod 中的 autoDispose 是否与 Flutter 中的处理生命周期相同?

[英]Does autoDispose in riverpod works same as dispose lifecycle in Flutter?

Does autoDispose in Riverpod's StateProvider disposes controllers? Riverpod 的 StateProvider 中的 autoDispose 是否处理控制器? Does both the following statements works similarly?以下两个陈述的作用是否相似?

final _controller = StateProvider.autoDispose((ref) => PageController());

or或者

final _controller = PageController();
    
      @override
      void dispose() {
        _controller.dispose();
        super.dispose();
      }

autoDispose modifier, as the name suggests, disposes call of the resources when the provider is not used, it simply frees up memory without us specifying any dispose function. autoDispose 修饰符,顾名思义,在不使用提供程序时处理资源调用,它只是释放 memory 而无需我们指定任何处理 function。

One example that may help you for example when you navigate into another page in which you have a provider with autoDispose, if you go back to your first page your provider data will reset, without autoDispose, everything will be saved.一个可能对您有帮助的示例,例如,当您导航到另一个页面,其中您有一个提供程序具有 autoDispose 时,如果您 go 回到您的第一页,您的提供程序数据将重置,没有 autoDispose,所有内容都将被保存。

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

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