Issue
Recently Flutter team announced the Dart language now supports sound null safety! and is available in Dart 2.12 and Flutter 2. I want to migrate the app code to null safety.
How to migrate my packages to null safety,
It would be great if someone could give instructions about migrating to null-safety.
Solution
-
Run
flutter upgrade
in the terminal to upgrade Flutter -
Run
dart migrate
to run the dart migration tool -
Solve all errors which the migration tool shows
-
Run
flutter pub outdated --mode=null-safety
to print all outdated
packages
You can see if the packages you depend upon support null-safety.
- Run
flutter pub upgrade --null-safety
to upgrade all packages
automatically - Check the code for errors and solve them
- Run
dart migrate
again and it should now be successful. Follow the
link to check out the proposed changes - Press the
"Apply Migration"
button - Check the code for errors again and fix them
Congratulations, when finished you should now be able to run the app with sound null-safety.
Run flutter run
in the command line and the application should run with the command line displaying:
Answered By – Javeed Ishaq
Answer Checked By – David Marino (FlutterFixes Volunteer)