When making a package, I am often confused as to whether I should use the any
constraint.
I know that for:
library packages, I should specify clear version constraints so that users of my libraries know the version of my transitive dependencies,
application packages, I should use any
and check in my pubspec.lock
lockfile so that others can run my application,
but there is a grey area for:
applications that are meant to be extended, such as codelabs, tutorials, templates, examples, and others.
applications that also have re-usable libraries; that is, packages that have a lib
directory for common functionality that doesn't make sense to put in a separate package, but also a web
directory for a full-fledged application.
Question: When exactly should I use the any
version constraint, and when should I fully specify the version constraint for Pub packages?
To update your dependencies to the latest version you can do the following: Use pub upgrade to update to the latest package versions that your pubspec allows. To identify dependencies in your app or package that aren't on the latest stable versions, use pub outdated .
A dependency is another package that your package needs in order to work. Dependencies are specified in your pubspec. You list only immediate dependencies—the software that your package uses directly. Pub handles transitive dependencies for you.
There are two types of dependencies, one is regular and the other is dev. dependencies: Regular dependencies are listed under dependencies:—these are packages that anyone using your package will also need.
applications that are meant to be extended, such as codelabs, tutorials, templates, examples, and others.
Since these are often going to be copy-pasted as the basis of normal application packages, I'd use the any
constraint and check in a lockfile to set a good example.
applications that also have re-usable libraries; that is, packages that have a
lib
directory for common functionality that doesn't make sense to put in a separate package, but also aweb
directory for a full-fledged application.
All applications should put their code in the lib
directory. The web
directory should just contain the entrypoint(s). So this is just a standard application package, which should use the any
constraint and check in a lockfile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With