简体   繁体   English

升级项目 Flutter SDK,迁移到空安全 - 包中的编译时错误

[英]Upgrading projects Flutter SDK, migration to null-safety - compile time errors in packages

We have decided to upgrade the Flutter version from 1.22 to 2.0 (migrating to null-safety) in an existing project.我们决定在现有项目中将 Flutter 版本从 1.22 升级到 2.0(迁移到零安全)。
We checkout Flutter v2.0.0 and then run the following command:我们检查 Flutter v2.0.0 然后运行以下命令:

dart pub upgrade --null-safety

Flutter nicely resolves all dependency conflicts and sets new versions for packages. Flutter 很好地解决了所有依赖冲突并为包设置了新版本。
Without changing min environment SDK in pubspec.yaml (staying at ">2.10.0 <3.0.0") we fix all breaking changes in the code.在不更改 pubspec.yaml 中的最小环境 SDK(停留在 ">2.10.0 <3.0.0")的情况下,我们修复了代码中的所有重大更改。

All errors in vs code disappear so we can compile the code. VS 代码中的所有错误都消失了,所以我们可以编译代码。 But, when we do compile we get errors from packages eg reorderables, fl_chart, flutter_svg etc. stating some classes are undefined.但是,当我们编译时,我们会从包中得到错误,例如 reorderables、fl_chart、flutter_svg 等,说明某些类是未定义的。 It seems like packages were compiled with a higher SDK version and they weren't set min SDK version to match the one that they were compiled with.似乎软件包是使用更高的 SDK 版本编译的,并且它们没有设置为最小 SDK 版本以匹配它们编译的版本。

So the package states it can be compiled with Flutter 2.10.0 but in reality, it fails to compile because in this version of Flutter it is missing some necessary imports.所以 package 声明它可以用 Flutter 2.10.0 编译,但实际上,它无法编译,因为在这个版本的 Flutter 中它缺少一些必要的导入。

My question is, is this a problem of packages or a problem in my way of processing with migration?我的问题是,这是包的问题还是我处理迁移的方式有问题?
Is it that packages are lacking properly set min SDK?是否缺少正确设置最小 SDK 的软件包?

My conclusion is that most packages are lacking correctly set SDK version constraints.我的结论是,大多数软件包都缺少正确设置的 SDK 版本约束。 It seems authors usually compile packages for a certain version and do not check min SDK version required.似乎作者通常为某个版本编译软件包,并且不检查所需的最低 SDK 版本。 When running dependency resolver it seems to solve dependencies but in compile time it fails.运行依赖解析器时,它似乎解决了依赖关系,但在编译时它失败了。

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

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