flutter migration to null-safety - Bad state: Error: package has unmigrated dependencies - own screens

flutter migration to null-safety - Bad state: Error: package has unmigrated dependencies - own screens

我尝试将一个 flutter 项目迁移到 null-safety。我得到的反馈是所有软件包都是兼容和升级的。 当我 运行 飞镖迁移时,我自己编写的屏幕(我想迁移)被批评为未迁移的依赖项。

1)

 $ dart pub outdated --mode=null-safety
    Resolving...
    Showing dependencies that are currently not opted in to null-safety.
    [x] indicates versions without null safety support.
    [+] indicates versions opting in to null safety.
    
    Computing null safety support...
    All your dependencies declare support for null-safety.
$ dart pub upgrade --null-safety
  ...
  dio: ^4.0.5-beta1 -> ^4.0.4
  firebase_core: ^1.11.0 -> ^1.12.0
$ dart pub get
  ...
  Got dependencies!
$ dart migrate
Analyzing project...
[-------------------------------------------------/]
Bad state: Error: package has unmigrated dependencies.

Before migrating your package, we recommend ensuring that every library it
imports (either directly or indirectly) has been migrated to null safety, so
that you will be able to run your unit tests in sound null checking mode.  You
are currently importing the following non-null-safe libraries:

  package:prosz/Screens/bottombar/tabbar.dart  
  package:prosz/Screens/chat.dart
  package:brosz/Screens/chatPost.dart
  ...
Please upgrade the packages containing these libraries to null safe versions
before continuing.  To see what null safe package versions are available, run
the following command: `dart pub outdated --mode=null-safety`.

To skip this check and try to migrate anyway, re-run with the flag
`--skip-import-check`.

版本

$ flutter --version
Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (7 weeks ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1

pubspec

environment:
  sdk: ">=2.1.0 <3.0.0"

将 pubspec 更改为 sdk: ">=2.12.0 <3.0.0" 修复了问题,但导致:

311 analysis issues found 
..... 
The migration tool didn't start, due to analysis errors.

The following steps might fix your problem:
1. Set the lower SDK constraint (in pubspec.yaml) to a version before 2.12.
2. Run `dart pub get`.
3. Try running `dart migrate` again.

在您的 pubspec 中将 2.1.0 更改为 2.12.0

这是我自己的回答:运行 "dart migrate" form ">=2.1.0 <3.0.0" and ">=2.12.0" 时发现的分析问题数量不一样<3.0.0"。 当我从“>=2.12.0 <3.0.0”运行时还有很多。 (尤其是错误的,因为 dart 认为代码已经被迁移)

所以正确的方法是从“>=2.1.0 <3.0.0”开始“dart migrate”,修复手工发现的分析问题。这些分析问题主要是升级包的语法变化,可以在pub.dev、各自的变更日志

中找到

如果你从 flutter 2.8.1 开始迁移,你就会遇到这个麻烦。