Flutter 2 is here and with web support on stable channel and new desktop crispy goodies it came a long-awaited feature: sound null safety! But... we're not here to talk in depth about it, but only how to migrate your code to Flutter 2 which, if you don't want null safety, it's pretty easy.
1. Check for breaking changes and change your code accordingly
With great releases comes great breaking changes (Uncle Ben).
Jokes aside you should take a look here and check if some of your code would be affected by this update. be also aware that with by upgrading to Flutter 2 all your projects will be affected if you're not using some third-party Flutter version control methods.
2. flutter upgrade
That's the very first thing to do, just give the command
Just wait for the download to finish and voila! Flutter 2 is here!
3. Check out your dependencies
Flutter 2 lets you upgrade your dependencies because, obviously, it now supports sound null safety so, get on your project
pubspec.yaml file and check for updates.
You should need to manually update most of your dependencies because most packages got a "major" release with Flutter 2 so refer to pub.dev on how to update your libraries.
You did it! But for having the complete package you should also need to set your dart version to support null safety!
4. Feeling brave?
This could be pretty time-consuming and giving you some issues but you should do it because it will geive you a best insight on possible issues and null exceptions.
First you'll need to update the minimum dart version on your pubspec.yaml file:
environment: sdk: ">=2.12.0<3.0.0" //This line should look like this
Then do a little
flutter clean and
Now pretty much 70% of your code will have issues. Don't worry, it's normal, refert to this page to know how to migrate your code and adding all necessary identifiers.
Be also aware that if you add sound null safety to your project all your dependencies must have it so if you have even one library has not been updated your code will fail to run.
There, here's a little guide on how to migrate to Flutter 2. Wrapping up it's a pretty easy task if you don't enable sound null safety, which is absolutely the most difficult and time-consuming task. My advice is that if you have old, very big projects, just update Flutter and your dependencies, all new projects, however should have sound null safety.
Top comments (0)