4

After I recently upgraded flutter to 3.0.0 and flutter_lints to 2.0.1, I started getting the following warning:

Depend on referenced packages.

Here, the dependency that is imported is defined in the pubspec.yaml of another module that the current module already depends on. In other words, the dependency flow is as follows:

A (module that gives warning and imports D) -> B -> D

I don't understand why I see this warning. Just because module A doesn't directly depend on library D? What should I do with this warning? How can I eliminate it without ignoring the rule in analysis_options.yaml file?

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
  • You can suppress rules for files or lines of code explained in the [static analysis guide](https://dart.dev/guides/language/analysis-options#suppressing-rules-for-a-file). – Merlin Attila Fejzuli May 14 '22 at 00:53
  • @MerlinAttilaFejzuli yep, I'm aware of it. However, I don't believe I should see this warning in the first place. – Ugurcan Yildirim May 14 '22 at 11:03

7 Answers7

3

Had the same warning.

In my case it was caused by flutter_localizations.

I realized I put

flutter_localizations:
    sdk: flutter

below dev_dependencies and not below dependencies in pubspec.yaml.

Maybe you have the same or similar problem.

MLZ
  • 33
  • 5
  • My ```local_auth: ^2.1.0``` also gives this warning. It is in dependencies, instead of dev_dependencies. So strange. – Krahmal Jun 23 '22 at 01:00
2

This error recommends that in pubspec.yaml file, you add the package in the dev-dependencies or dependencies(depending on the use case as instructed on the package docs). Checkout this

enter image description here

Also, make sure you are importing the right package in the right format as required to in the package documentation.

2

Check to make sure the package is under "dependencies" and not (for example) under "dev_dependencies"

user1603721
  • 188
  • 3
  • 12
1

You're seeing the intended behavior of that lint. Without that lint you would get an error if the included library was not depended upon, and you rightly assume that a transitive dependency is enough to build.

The lint is likely here to protect against the cases where a dependency has either removed the dependency or changed to a version with breaking changes, such that your transitive use would either break or unintentionally change.

Each of the lints contain a brief description of why they exists.

lime
  • 11
  • 2
  • 1
    No, this lint `depend_on_referenced_packages` warns about used imports that do not have a corresponding entry in the pubspec file. "Depend on" means to have it in your pubspec.yaml `dependencies:` section. – lime May 24 '22 at 08:30
  • I was wrong, you are right! – Csaba Toth May 24 '22 at 14:15
1

In my case, they were all packages that were required (and thus included) by other packages that were listed in pubspec.yaml but since I was using them myself directly, I had to explicitly add them to pubspec.yaml as direct-dependents.

Once I added the offending packages to pubspec.yaml, error was gone.

0

analysis_options.yaml

include: package:flutter_lints/flutter.yaml

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

linter:
  rules:
    depend_on_referenced_packages: false
0

I had all the records in pubspec.yaml In my case it was caused by the Android Studio itself. I had to restart it and all was started to work fine

Denis Rudov
  • 833
  • 8
  • 16