简体   繁体   English

Flutter:Connectivity Widget Wrapper Provider 错误

[英]Flutter: Connectivity Widget Wrapper Provider error

I've added ConnectivityWrapperWidget with my custom offlineWidget.我已经添加了 ConnectivityWrapperWidget 和我的自定义 offlineWidget。 I'm getting this error, while running the app运行应用程序时出现此错误

Error: Could not find the correct Provider above this ConnectivityWidgetWrapper Widget错误:在此 ConnectivityWidgetWrapper 小部件上方找不到正确的提供程序

This likely happens because you used a BuildContext that does not include the provider of your choice.这可能是因为您使用了不包含您选择的提供程序的BuildContext There are a few common scenarios:有几种常见的场景:

  • The provider you are trying to read is in a different route.您尝试读取的提供程序位于不同的路径中。

    Providers are "scoped".提供者是“有范围的”。 So if you insert of provider inside a route, then other routes will not be able to access that provider.因此,如果您在路由中插入提供者,则其他路由将无法访问该提供者。

  • You used a BuildContext that is an ancestor of the provider you are trying to read.您使用了一个BuildContext ,它是您尝试读取的提供程序的祖先。

    Make sure that ConnectivityWidgetWrapper is under your MultiProvider/Provider.确保 ConnectivityWidgetWrapper 在您的 MultiProvider/Provider 下。 This usually happen when you are creating a provider and trying to read it immediately.这通常发生在您创建提供程序并尝试立即读取它时。

    For example, instead of:例如,而不是:

     Widget build(BuildContext context) { return Provider<Example>( create: (_) => Example(), // Will throw a ProviderNotFoundError, because `context` is associated // to the widget that is the parent of `Provider<Example>` child: Text(context.watch<Example>()), ), }

    consider using builder like so:考虑像这样使用builder

     Widget build(BuildContext context) { return Provider<Example>( create: (_) => Example(), // we use `builder` to obtain a new `BuildContext` that has access to the provider builder: (context) { // No longer throws return Text(context.watch<Example>()), } ), }

I don't get it.我不明白。 Can somebody explain, what is the issue有人可以解释一下,这是什么问题

Try to use builder instead of child, as your error suggests.正如您的错误所暗示的那样,尝试使用 builder 而不是 child。 If it doesn't help, show some code.如果没有帮助,请显示一些代码。

在添加 ConnectivityWrapper 时,如果使用自定义的 offlineWidget(),则需要将 ConnectivityAppWrapper 添加为 MaterialApp 的父级。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 错误:找不到正确的提供程序<user>在此 Wrapper Widget 上方</user> - Flutter Error: Could not find the correct Provider<User> above this Wrapper Widget Flutter 错误:找不到正确的提供者<myuser>在这个包装器小部件上方</myuser> - Flutter Error: Could not find the correct Provider<MyUser> above this wrapper widget Flutter 提供程序错误:当继承的小部件更改时 - Flutter provider error: When an inherited widget changes 使用 Flutter 中的 package 与提供程序的连接 - Using connectivity package in Flutter with provider 颤振提供者错误:在此小部件上方找不到正确的提供者 - flutter provider error : Could not find the correct provider above this widget Flutter 中的提供程序出现错误“无法在此 X Widget 上方找到正确的提供程序” - Provider in Flutter with error "Could not find the correct provider above this X Widget" Flutter 提供程序和小部件生命周期 - Flutter provider and widget lifecycle Flutter 连接:compileDebugJavaWithJavac 错误 - Flutter connectivity:compileDebugJavaWithJavac error Flutter 使用 Provider 时出现“EditableText 上方不存在覆盖小部件”错误 - Flutter 'No Overlay widget exists above EditableText' error when using Provider 错误:找不到正确的提供者<clientsprovider>在 flutter 中的此客户小部件上方?</clientsprovider> - Error: Could not find the correct Provider<ClientsProvider> above this Clients Widget in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM