[英]What are dependencies of a state in flutter
I am trying to understand the method didChangeDependencies and according to the definition我试图了解方法didChangeDependencies并根据定义
It is Called when a dependency of this State object changes.
当此 State object 的依赖关系发生变化时调用它。
what do they mean by this.他们是什么意思。 My guess is when properties in the state you manage per screen change.
我的猜测是您在每次屏幕更改时管理 state 中的属性。 Am I right.
我对吗。 Please I would love to understand better.
请我想更好地理解。
Try to think of it the same as initState
but just a little later.尝试将其与
initState
相同,但稍晚一些。
initstate
is called before the state loads its dependencies and for that reason no context
is available and you get an error for that if u use context
in initstate
. initstate
在 state 加载其依赖项之前被调用,因此没有可用的context
,如果您在initstate
中使用context
,则会出现错误。 However, didChangeDependencies
is called just few moments after the state loads its dependencies and context
is available at this moment so here you can use context
.但是,在 state 加载其依赖项后不久就调用了
didChangeDependencies
,并且此时context
可用,因此您可以在此处使用context
。
In case BuildContext.dependOnInheritedWigetOfExactType
called, or in case the widget is been moved inside of the element tree, didChangeDependencies
will is always called.如果调用了
BuildContext.dependOnInheritedWigetOfExactType
,或者如果小部件被移动到元素树内,则将始终调用didChangeDependencies
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.