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.
To allow nullable type in Dart, you must add a “?” (quotation mark) at the type identifier. This action tells dart that this value is nullable. It may have or have not a value.
You can specify that a type of a variable is nullable (e.g. int? i ), and only then can they contain either a null or a value of the defined type.
The keyword for Null in the programming language Dart is null. Null means a variable which has no values assign ever and the variable is initialized with nothing like.
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.
flutter pub upgrade --null-safety
to upgrade all packages
automaticallydart migrate
again and it should now be successful. Follow the
link to check out the proposed changes"Apply Migration"
buttonCongratulations, 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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With