'Unexpected Flutter linter warning: depend_on_referenced_packages
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?
Solution 1:[1]
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.
Solution 2:[2]
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.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | |
| Solution 3 | ë”í…Œí¬ë¹Œê°œë°œíŒ€ |
