The following steps requires dart
2.19tool or lower because the dart
migrate tool is removed in version 3:
To update the project to null safety follow these steps:
Side note: change the flutter version in pubsec.yaml, make new project and copy the following line:
sdk: ">=2.19.6 <3.0.0"
Then follow the steps:
- Run
flutter upgradein the terminal to upgrade Flutter - Run
dart migrateto run the dart migration tool. - Solve all errors which the migration tool shows.
- Run
flutter pub outdated --mode=null-safetyto print all outdated packages. - Run
flutter pub upgrade --null-safetyto upgrade all packages automatically. - Check the code for errors and solve them (Very important).
- Run
dart migrateagain and it should now be successful. Follow the link to checkout the proposed changes. - Press the “Apply Migration” button.
- Check the code for errors again and fix them.
Your project should be updated now.
Referenced from this website.