gpt4 book ai didi

flutter - 什么时候在设置状态之前检查已安装?

转载 作者:IT王子 更新时间:2023-10-29 07:13:05 25 4
gpt4 key购买 nike

文档 here说:

It is an error to call this method after the framework calls dispose. You can determine whether it is legal to call this method by checking whether the mounted property is true.

我从未见过检查 mounted 属性的 Flutter 示例,那么我们应该在哪些情况下实际检查它呢?

最佳答案

when code calls setState() from a timer or an animation callback. The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.

引用自 SDK 源码

关于flutter - 什么时候在设置状态之前检查已安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53465060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com