我正在使用 Bloc 模式构建一个基本的 Flutter 应用程序。到目前为止,这是我的结构。
MainProvider
包含,我可以在每个子页面Repository
中传递它(基本上每页一个 Bloc)。Bloc
问题是,如果我想这样访问MainProvider
:
final provider = MainProvider.of(context);
从 MenuPage 或 OtherPage,我通过从 HomePage 导航访问
Navigator.push(context,
MaterialRoutePage(
(context) => MenuPage(homePageParam); //or OtherPage(homePageParam)
);
该.of
方法返回null
。
我怎样才能正确访问它InheritedWidget
?我应该做另一种类型的Navigator.push
吗?