简体   繁体   English

flutter 中的 state 的依赖关系是什么

[英]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.

相关问题 Flutter 中的“脏”是什么?是什么导致了这个“脏”的 state? - What is "dirty" in Flutter & what is causing this "dirty" state? Flutter Bloc state 无论如何都不更新 - Flutter Bloc state does not update no matter what 当在 flutter 块中发出新的 state 时,旧的 state 会发生什么情况? - What happens to the old state when a new state is emitted in flutter bloc? Flutter 应用程序中的临时状态和应用程序状态是什么? - What is called as Ephemeral state and App state in Flutter Application? 我们在 flutter 中 dev_dependencies 下添加的内容 - What we add under dev_dependencies in flutter Flutter - 更新了所有 Firebase 依赖项 - 状态不佳:无法在不存在的 DocumentSnapshotPlatform 上获取字段 - Flutter - Updated all Firebase Dependencies - Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist flutter 迁移到空安全 - 错误 state:错误:package 具有未迁移的依赖项 - 自己的屏幕 - flutter migration to null-safety - Bad state: Error: package has unmigrated dependencies - own screens Flutter 以不同方式创建状态有什么区别? - Flutter what is the difference between creating state in different manner? Flutter 的 HERE SDK 对 null 安全的支持状态如何? - What's the state of support for null safety for the HERE SDK for Flutter? FLUTTER:对于无限数量的嵌套屏幕,最好的 state 管理方法是什么 - FLUTTER: What is the best state management approach for infinite number of nested screens
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM