Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(9)
只需显式添加包即可。
flutter pub add flutter_gen
flutter pub get
有关更多信息,请参阅 https://dart-lang.github.io/linter/lints/depend_on_referenced_packages.html
Just add the package explicitly.
flutter pub add flutter_gen
flutter pub get
For more info, see https://dart-lang.github.io/linter/lints/depend_on_referenced_packages.html
我不知道如何仅忽略生成的包,但这就是完全关闭规则的方法:
analysis_options.yaml
。有关此文件的其他信息可以在 https://dart.dev/guides/language 找到/分析选项
I don't know how to ignore only generated packages, but this is how you turn off the rule entirely:
analysis_options.yaml
in your project root.Additional information about this file can be found at https://dart.dev/guides/language/analysis-options
根据文档,似乎仅依赖
flutter_localizations
是不够的。您的依赖项应该如下所示:Based on the documentation, it seems that just having a dependency on
flutter_localizations
only is not enough. Your dependencies should look like this:对我来说,发生此错误是因为我不小心将包名称放入了 dev_dependencies 部分。将我的包名称放入依赖项部分解决了我的问题。
For me, this error occurs because I accidentally put my package name in the dev_dependencies section. Putting my package name in dependencies section fixed my problem.
我在应用程序中的十几个地方使用了
collection.dart
,最近在 Flutter 3.0 升级之后,这个 lint 开始出现。我认为depend_on_referenced_packages
是一个非常有用的 lint,可以警告您不必要的导入。我永远不会为该项目完全关闭它(@EzPizza 的回答)。您可以通过将以下注释添加到文件中来抑制受影响文件的 lint:
//ignore_for_file: dependent_on_referenced_packages
但最好修复问题的根本原因并将指示的依赖项包含到您的
中>pubspec.yaml
。例如@mkobuolys 的建议。I'm using
collection.dart
more than a dozen places in my app and recently after the Flutter 3.0 upgrade this lint started to pop up for me. I thinkdepend_on_referenced_packages
is a really useful lint to warn you about unnecessary imports. I would never turn it off entirely for the project (@EzPizza's answer).You can suppress the lint for an affected file by adding this comment to the file:
// ignore_for_file: depend_on_referenced_packages
But it's even better to fix the root cause of the problem and include the indicated dependencies into your
pubspec.yaml
. Like for example what @mkobuolys proposes.对我来说,我不小心将包
url_launcher: ^6.1.7
放在dev_dependency:
解决方案:
我 从
dev_dependency
中删除该软件包,并在dependency:
下面添加它For me, I accidentally put the package
url_launcher: ^6.1.7
underdev_dependencies:
Solution:
I removed the package from
dev_dependencies
and added it belowdependencies:
我只是发布这个,因为其他答案要么没有帮助我,要么我不理解它们。
我在不同的包(即 page_transition)上收到了相同的警告。以下是我发现问题发生的原因:
这意味着您应该寻找解决方案而不是忽略它。
这是我修复它的方法:
我转到 pubspec.yaml 并在依赖项下添加了以下内容:
您可以为您必须查找的包添加依赖项。我刚刚在谷歌上搜索了“flutter app_localizations”,结果出现了,您可以在安装选项卡下看到最新版本。
本地化 2.1.0
因此,如果您正在使用该软件包,例如,您将必须添加
I'm only posting this because the other answers either didn't help me or I didn't understand them.
I got the same warning on a different package, namely page_transition. Here's what I found on why the problem occurs:
Meaning you are right to look for a solution other than to ignore it.
Here's how I fixed it:
I went to pubspec.yaml and added the following under dependencies:
You can add the dependency for your package which you would have to look up. I just googled "flutter app_localizations" and this came up, you can see the latest version under the Installing tab.
localization 2.1.0
So, if you're using that package, as an example, you would have to add
对我来说,这是因为我收到此警告的软件包尚不支持 flutter 3。
for me it was because the packages i was having this warning on didn't support flutter 3 yet.
这是官方链接,
您应该直接依赖而不是间接依赖。
this is the official link
you should direct dependency not indirectly dependency.