据我了解,它将在initState之后和InheritedWidget中的任何更改之后被触发,但是这些更改是什么?我认为了解什么变化触发didChangeDependencies很重要,因此我们可以了解何时以及如何正确使用它. 解决方案当Flutter调用 updateShouldNotify()并返回true,然后调用didChangeDependencies通知先前在build()中请求继承的窗口小部件的窗口小部件. 如果 updateShouldNotify自上次调用以来其状态已更改,则应返回true.After reading the docs here and the State lifecycle here, I am still not sure about how didChangeDependencies works.As far as I understand it will be triggered after initState and after any change in an InheritedWidget, but what are these changes? I think it's important to understand what changes trigger didChangeDependencies, so we can understand when and how to use it properly. 解决方案 When Flutter calls updateShouldNotify() and it returns true, then widgets that requested an inherited widget in build() previously are notified by didChangeDependencies being called. updateShouldNotify should return true if its state changed since the last time it was called. 这篇关于了解Flutter didChangeDependencies机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 13:10