gpt4 book ai didi

flutter - Flutter 的 pubspec.yaml 中依赖版本号前的脱字符号 (^) 是什么?

转载 作者:IT老高 更新时间:2023-10-28 12:29:14 39 4
gpt4 key购买 nike

在我的 Flutter 项目的 pubspec.yaml 文件中,某些依赖项的版本号之前有一个插入符号 (^)。

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.5

它的目的是什么?什么意思?

备注

最佳答案

插入符号 ( ^ ) 用于 pub dependencies在 Dart 中表示允许的版本号范围。具体来说,从指定版本到(但不包括)下一个非破坏性版本的任何版本都可以。

  • 所以^3.1.5'>=3.1.5 <4.0.0' 相同
  • 还有 ^1.2.3'>=1.2.3 <2.0.0' 相同

它是较长形式的简写。

^也就是说,我想自动使用来自 Pub 的最新包,只要该更新不会破坏我的应用程序中的任何内容。

注意事项

1.0.0 以下版本的说明

原来我也这么认为

  • ^0.1.2'>=0.1.2 <1.0.0' 相同(错误!)

但是,这是对 Semantic Versioning 的错误理解。 .当主版本号为 0 时(如 00.1.2 中),其含义是 API 不稳定,即使是较小的版本号更改(如 10.1.2 中)也可能表示重大更改。

Semantic Versioning文章指出:

Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.

还有

How should I deal with revisions in the 0.y.z initial developmentphase?

The simplest thing to do is start your initial development release at0.1.0 and then increment the minor version for each subsequent release.

因此,修正后的形式如下:

  • ^0.1.2'>=0.1.2 <0.2.0' 相同

感谢 Günter Zöchbauer指出我的错误。

另见

关于flutter - Flutter 的 pubspec.yaml 中依赖版本号前的脱字符号 (^) 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53563079/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com