如何避免 lint 问题“依赖于引用的包”对于 gen_l10n/app_localizations.dart

发布于 2025-01-10 21:02:28 字数 1468 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

地狱即天堂 2025-01-17 21:02:28

只需显式添加包即可。

  1. 运行 flutter pub add flutter_gen
  2. 运行 flutter pub get

有关更多信息,请参阅 https://dart-lang.github.io/linter/lints/depend_on_referenced_pa​​ckages.html

Just add the package explicitly.

  1. run flutter pub add flutter_gen
  2. run flutter pub get

For more info, see https://dart-lang.github.io/linter/lints/depend_on_referenced_packages.html

千秋岁 2025-01-17 21:02:28

我不知道如何仅忽略生成的包,但这就是完全关闭规则的方法:

  1. 在项目根目录中创建一个文件 analysis_options.yaml
  2. 粘贴此:
include: package:flutter_lints/flutter.yaml

linter:
  rules:
    depend_on_referenced_packages: false

有关此文件的其他信息可以在 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:

  1. Create a file analysis_options.yaml in your project root.
  2. Paste this:
include: package:flutter_lints/flutter.yaml

linter:
  rules:
    depend_on_referenced_packages: false

Additional information about this file can be found at https://dart.dev/guides/language/analysis-options

浅暮の光 2025-01-17 21:02:28

根据文档,似乎仅依赖 flutter_localizations 是不够的。您的依赖项应该如下所示:

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  intl: ^0.17.0 # Add this line

Based on the documentation, it seems that just having a dependency on flutter_localizations only is not enough. Your dependencies should look like this:

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  intl: ^0.17.0 # Add this line
苏别ゝ 2025-01-17 21:02:28

对我来说,发生此错误是因为我不小心将包名称放入了 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.

魂牵梦绕锁你心扉 2025-01-17 21:02:28

我在应用程序中的十几个地方使用了collection.dart,最近在 Flutter 3.0 升级之后,这个 lint 开始出现。我认为 depend_on_referenced_pa​​ckages 是一个非常有用的 lint,可以警告您不必要的导入。我永远不会为该项目完全关闭它(@EzPizza 的回答)。

您可以通过将以下注释添加到文件中来抑制受影响文件的 lint:

//ignore_for_file: dependent_on_referenced_pa​​ckages

但最好修复问题的根本原因并将指示的依赖项包含到您的 中>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 think depend_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.

彼岸花似海 2025-01-17 21:02:28

对我来说,我不小心将包 url_launcher: ^6.1.7 放在 dev_dependency:

解决方案:

dev_dependency中删除该软件包,并在dependency:下面添加

For me, I accidentally put the package url_launcher: ^6.1.7 under dev_dependencies:

Solution:

I removed the package from dev_dependencies and added it below dependencies:

暗喜 2025-01-17 21:02:28

我只是发布这个,因为其他答案要么没有帮助我,要么我不理解它们。

我在不同的包(即 page_transition)上收到了相同的警告。以下是我发现问题发生的原因:

导入包时,请将其依赖项添加到您的 pubspec 中。

显式依赖于您引用的包可确保它们始终存在,并允许您对它们施加依赖约束以防止发生重大更改。

这意味着您应该寻找解决方案而不是忽略它。

这是我修复它的方法:
我转到 pubspec.yaml 并在依赖项下添加了以下内容:

dependencies:
  page_transition: ^2.0.9

您可以为您必须查找的包添加依赖项。我刚刚在谷歌上搜索了“flutter app_localizations”,结果出现了,您可以在安装选项卡下看到最新版本。
本地化 2.1.0

因此,如果您正在使用该软件包,例如,您将必须添加

dependencies:
  localization: ^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:

When importing a package, add a dependency on it to your pubspec.

Depending explicitly on packages that you reference ensures they will always exist and allows you to put a dependency constraint on them to guard you against breaking changes.

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:

dependencies:
  page_transition: ^2.0.9

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

dependencies:
  localization: ^2.1.0
末骤雨初歇 2025-01-17 21:02:28

对我来说,这是因为我收到此警告的软件包尚不支持 flutter 3。

for me it was because the packages i was having this warning on didn't support flutter 3 yet.

无所的.畏惧 2025-01-17 21:02:28

这是官方链接

您应该直接依赖而不是间接依赖。

this is the official link

you should direct dependency not indirectly dependency.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文