dart – Flutter:从没有上下文的InheritedWidgets访问数据?

我看到我可以在build()方法中访问InheritedWidgets,如下所示:final inheritedWidget = ChronoApp.of(context);但是如果我想在其他地方访问它,比如在initState()中没有上下文.我该怎么做?

解决方法

根据此文档,上下文应该在initState中使用上下文getter.

https://docs.flutter.io/flutter/widgets/State/context.html

The framework associates State objects with a BuildContext after creating them with StatefulWidget.createState and before calling initState.

相关文章

这篇文章主要讲解了“FlutterComponent动画的显和隐怎么实现...
这篇文章主要讲解了“flutter微信聊天输入框功能如何实现”,...
本篇内容介绍了“Flutter之Navigator的高级用法有哪些”的有...
这篇文章主要介绍“Flutter怎么使用Android原生播放器”,在...
Flutter开发的android端如何修改APP名称,logo,版本号,具体...
Flutter路由管理初识路由概念一.路由管理1.1.Route1.2.Mater...