Migrating to Flutter 2 fail

Viewed 4663

I have a project that is developed with Flutter v1.22.6 and was working great, after updating the flutter to v2.0.0 and reading the documentation, I've found out I can use dart migrate --apply-changes to fix issues that are related to flutter upgrade, By running the command I get dozens of errors and the error ends with:

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.

What is the simplest way to migrate the current project to the v2?

2 Answers

The problem is that you have already migrated to a newer version of dart. You can't migrate your projects from the new version, there is literally nothing to migrate to.

If you want to migrate your older projects (which are without null safety) to a new version, your dart version must be older than 2.12.0 version. In this case, consider changing the version in your pubspec.yaml file.

environment:
   sdk: '>=2.11.0 <3.0.0'

Then run the command in your terminal

> dart migrate --apply-changes

make sure you have following step by step migrate dart 2

and base on your error notification try to set in pubspec.yaml

environment:
  # Works in Dart 2 only.
  sdk: '>=2.0.0 <3.0.0'
Related