Migrating a large Flutter project to null safety
According to the guide at https://dart.dev/null-safety/migration-guide, migrating to null safety is straightforward. Let's try it on a large project.
So today I switched the sdk version to 2.12 in my pubspec.yaml, and 300+ compilation errors appeared. I tried the migration tool:
% dart migrate
Migrating /Users/anhtuan/git/[project name]
See https://dart.dev/go/null-safety-migration for a migration guide.
Analyzing project...
[--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\]
366 analysis issues found:
I thought it would auto-replace things for me. Instead, it listed the same compilation errors as the analyzer... At the end it said:
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.
More information: https://dart.dev/go/null-safety-migration
Then I tried to update dependencies to their null safety versions with dart pub outdated --mode=null-safety
, then using the upgrade command they suggested. But when running dart migrate
, it threw the same analyzer errors.
I guess I'll have to go through each and every single one of them manually...