停用和处置之间的区别?

Difference Between Deactivate and Dispose?

在Flutter中,StatefulWidget有dispose()deactivate()。它们有什么不同?

dispose 是确定的。 deactivate 不是。

deactivate 在小部件 可能 被释放时被调用。但这并不能保证。

调用 deactivate 但不调用 dispose 的典型情况是使用 GlobalKey.

在小部件树中移动小部件时

停用:

Called when object is removed from the tree. In some cases, the framework will reinsert the State object into another part of the tree (e.g., if the subtree containing this State object is grafted from one location in the tree to another). source

处置:

Called when this object is removed from the tree permanently. source

通过理解这两个句子,您会发现将从树中删除的小部件 暂时或永久 调用 deactivate,而 dispose 将 被删除的小部件永久

感谢 Antonio Oliveira 提供的链接,现在我明白了。