简体   繁体   English

flutter 迁移到空安全 - 错误 state:错误:package 具有未迁移的依赖项 - 自己的屏幕

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

I try to migrate a flutter project to null-safety.我尝试将 flutter 项目迁移到 null-safety。 I get the feedback that all packages are compatible and upgrated.我得到的反馈是所有软件包都是兼容和升级的。 When I run dart migrate, my own writen screens (which I want to migrate) are criticized as unmigrated dependencies.当我运行 dart migrate 时,我自己编写的屏幕(我想迁移)被批评为未迁移的依赖项。

1) 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`.

versions版本

$ 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"

changing pubspec to sdk: ">=2.12.0 <3.0.0" fixes the problem, but causes:将 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.

Change 2.1.0 to 2.12.0 in your pubspec在您的 pubspec 中将 2.1.0 更改为 2.12.0

here is my own answer: the number of analysis issues found are not the same when run "dart migrate" form ">=2.1.0 <3.0.0" and ">=2.12.0 <3.0.0".这是我自己的回答:运行“dart migrate”时发现的分析问题数量不一样,形成“>=2.1.0 <3.0.0”和“>=2.12.0 <3.0.0”。 There are much more when I run from ">=2.12.0 <3.0.0".当我从“>=2.12.0 <3.0.0”运行时,还有更多。 (and especially wrong ones, because dart thinks the code has already been migrated) (尤其是错误的,因为 dart 认为代码已经被迁移)

So the right way is to start "dart migrate" from ">=2.1.0 <3.0.0" and fix the analysis issues found by hand.所以正确的方法是从“>=2.1.0 <3.0.0”开始“dart migrate”并修复手动发现的分析问题。 These analysis issues are mainly syntax changes of the upgraded packages, which can be found on pub.dev, in the respective changelogs这些分析问题主要是升级包的语法变化,可以在pub.dev中找到,在各自的变更日志中

You get in this trouble if you start migration from flutter 2.8.1.如果您从 flutter 2.8.1 开始迁移,就会遇到这个麻烦。

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

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