Flutter:安装依赖报错doesn‘t support null safety

项目中需要引用http依赖,在pubspec.yaml文件中添加如下信息:

当同步时,报错信息如下:

[myflutter] flutter pub upgrade

Resolving dependencies...

The current Dart SDK version is 3.1.3.

Because myflutter depends on http >=0.2.8+2 <0.13.0-nullsafety.0 which doesn't support null safety, version solving failed.

The lower bound of "sdk: '<2.0.0 or >=2.0.0-dev.61.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.

For details, see https://dart.dev/null-safety


 

You can try the following suggestion to make the pubspec resolve:

* Try upgrading your constraint on http: flutter pub add http:^1.1.0

exit code 1

 大概的意思是,你当前的系统sdk版本是3.1.3,是支持空对象的安全技术,而你要引入的http的版本小于0.13.0,不支持空安全,所以两个不匹配,报错。

在这个区间的http包(http >=0.2.8+2 <0.13.0)不支持空安全

所以我们把引用的http包的版本号提升一下即可。

猜你喜欢

转载自blog.csdn.net/bdmh/article/details/134247223