无法找到正确的提供商
我正在进行一个实验,我想在其中使用两个源代码制作两个类似的应用程序。
我正在尝试在小部件树的顶部建立“自适应”状态,并且此状态(changeNotifier
)取决于应用程序(isapp1()
确定哪个应用)。
这是我正在使用的代码:
ChangeNotifierProvider(
create: (context) {
return isApp1() ? AppState1() : AppState2();
},
child: MaterialApp(
onGenerateRoute: isAdminApp()
? App1Router.generateRoute
: App2Router.generateRoute,
initialRoute: "/",
),
);
我尝试在树的低级别中使用提供商。
Error: Could not find the correct Provider<AppState1> above this Widget
当 代码> appstate2()直接而不是isapp1()? AppState1():AppState2()
我不遇到此错误。
I am doing an experiment, where I want to make two similar apps with single source code.
I am trying to make an "adaptive" State on top of the widget tree, and this state (ChangeNotifier
) depends on the application (isApp1()
determines which app is this ).
here's the code that I'm using:
ChangeNotifierProvider(
create: (context) {
return isApp1() ? AppState1() : AppState2();
},
child: MaterialApp(
onGenerateRoute: isAdminApp()
? App1Router.generateRoute
: App2Router.generateRoute,
initialRoute: "/",
),
);
when I try to read the state using Provider.of in the low levels of the tree I am facing the error:
Error: Could not find the correct Provider<AppState1> above this Widget
Note: when I put AppState1()
or AppState2()
directly instead of isApp1() ? AppState1() : AppState2()
I don't face this error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论