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

Issue

I try to migrate a flutter project to 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.

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:

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.

Solution

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".
There are much more when I run from ">=2.12.0 <3.0.0". (and especially wrong ones, because dart thinks the code has already been migrated)

So the right way is to start "dart migrate" from ">=2.1.0 <3.0.0" and fix the analysis issues found by hand. These analysis issues are mainly syntax changes of the upgraded packages, which can be found on pub.dev, in the respective changelogs

You get in this trouble if you start migration from flutter 2.8.1.

Answered By – Bernhard

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.