0

我正在使用 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吗?

4

0 回答 0