Dan’s Quick Flutter 2 Migration Guide

Daniel Carneiro
3 min readJun 3, 2021

Some of you built the app using an older version of flutter, the current version I have is 1.22.6 so latest from version 1 of flutter.

You might already know this but, create a new branch before doing this work :)

Upgrade your flutter version

This should upgrade your dar-sdk version as well (min version 2.12.0)

flutter upgrade
/// In case you can't run that command recheck you are using the stable version
flutter channel stable

To upgrade the packages run this:

dart pub outdated --mode=null-safety

If that does not work you can run this command to find out what packages are not null-safe ready:

dart pub upgrade --null-safety --dry-run

F**k! there are plugins that still don’t have null-safety support, what can I do?

Obviously I now have a tone of plugins that do not have null-safety support, so I tried to find GitHub versions of those plugins with null-safety until I wait for an official version to be released for those plugins.

For some plugins I decided to keep them in the root folder of the project as its easier for me to later on remember which ones I need to change.

For other plugins I had to manually add the null-safety support, here’s how you can do it. (this applies to plugins and projects)

dart pub upgrade — null-safety — dry-run

Then update the dependencies to latest (if possible) then run this:

dart migrate

This will give you a link to access the dart migration tool which might do all the work without your intervention (not every time though but still better than nothing).

NOTE: If you have shared custom plugins that depend on the project you want to migrate, make sure you make that change on the plugins first.

I have one package that is not yet null safe ready, but I still want to use it

error example
dart migrate --skip-import-check

Now when I run the app it says that I have packages that are not null

Add this argument to the vscode `.vscode\launch.json`

"args": [
"--no-sound-null-safety"
]

or run on the console:

flutter run --no-sound-null-safety

References:

--

--