简体   繁体   English

在 pubspec.yaml 文件中指定库时使用 any 和 nothing 有什么区别?

[英]What's the difference between using any and nothing when specifying a library in pubspec.yaml file?

pubspec.yaml file: pubspec.yaml文件:

dependencies:
  foo: any
  bar:

When I run pub get command, the latest version of both the libraries are included in my pubspec.lock file.当我运行pub get命令时,这两个库的最新版本都包含在我的pubspec.lock文件中。 So, what's the difference between these two ways of specifying a library?那么,这两种指定库的方式有什么区别呢? And if there is none, then why any exists?如果any ,那为什么存在?

According to the Dart.dev page about package dependencies :根据关于 package 依赖项的 Dart.dev 页面

The string any allows any version.字符串 any 允许任何版本。 This is equivalent to an empty version constraint, but is more explicit.这相当于一个空版本约束,但更明确。 Although any is allowed, we don't recommend it.尽管允许任何一种,但我们不推荐这样做。

So, using the keyword any or an empty string is equivalent.因此,使用关键字any或空字符串是等效的。 However, any is more explicit and not recommended to be used, since if the API of the package you are depending on receives breaking changes in the future, your application won't work correctly.但是, any更明确,建议使用,因为如果您所依赖的 package 的 API 将来收到重大更改,您的应用程序将无法正常工作。

There's no difference between the two, any is more explicit.两者之间没有区别, any都更明确。

any任何

will let you update the dependency always to the latest version even if that's mean your project won't be compatible with the library or vice versa.将使您始终将依赖项更新为最新版本,即使这意味着您的项目将与库不兼容,反之亦然。

empty空的

will let you update the dependency but it will consider the project compatibility with the library or vice versa.会让你更新依赖关系,但它会考虑项目与库的兼容性,反之亦然。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM