A package import, such as import package:my_package/my_file.dart
, requires the my_package
package to be readily available
in the project during build, for the my_file.dart
source to be imported in the current source file.
The standard way to ensure this is the case is to add the dependency to my_package
in the pubspec.yaml
file:
- in the
dependencies
section, if the package is a runtime dependency, that is, the package is referenced from lib
or
bin
- in the
dev_dependencies
section, if the package is a development dependency, that is, the package is referenced from other
non-production directories, such as test
, test_resources
etc.
What is the potential impact?
If the package is not listed as a dependency in pubspec.yaml
, the build will only succeed if the package is somehow provided locally
at build time.
This can not only lead to build failures, but also to unexpected behavior, as the package may not be the same version as the one the code was
developed against, since the version is not locked in the pubspec.yaml
file and the standard package resolution mechanism of dart
pub get
is not used to deal with the lifecycle of this dependency.