Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Dart with Pub, when should I use the "any" version constraint for a dependency?

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?

like image 572
Juniper Belmont Avatar asked Apr 28 '13 20:04

Juniper Belmont


People also ask

How do I get the latest version of dependency in flutter?

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 .

What is dependency in dart?

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.

What are different types of dependencies in flutter?

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.


1 Answers

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 a web 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.

like image 170
Natalie Weizenbaum Avatar answered Oct 19 '22 10:10

Natalie Weizenbaum