I migrated a running app and a published package to null safety, and it was awesome!

About the author:_ Waleed Arshad is a core mobile technologist, a passionate cross-platform developer, and the first person from Pakistan to become a Google Developer Expert for Flutter. After graduating from FAST Karachi, he has been working in the industry for more than five years and is currently working in the Developer Experience team for Flutter at Tendermint. He also leads Pakistan’s Flutter community._

With the launch of Flutter 2, null safety was made available to Flutter’s stable channel. This post talks about my personal experiences with migrating my apps and packages to null safety, along with creating null-safe apps from scratch. In short, the results were amazing!

If you aren’t aware of Flutter’s null safety feature, check out the announcement of null safety. If you want to fully understand null safety, check out the Dart documentation for null safety.

This article describes two of my experiences with null safety:

  • Migrating an app and a package
  • Writing new code in a null-safe environment

Migrating an app and a package

When I first upgraded Flutter to version 2.0 (the one that supports null safety) and updated my Dart SDK version to 2.12 in my Flutter app’s pubspec.yaml file, I saw a lot of errors. I wanted to initially try a manual migration to null safety (that is, migrate without the migration tool), so I started to resolve the null safety errors manually — adding question marks and exclamation points all over my code. I did all of that work intentionally, just to understand all the hard work done by the Flutter team on the null safety migration tool to automate the process of changing and updating the code! After some experimentation, I reverted all the manual changes I’d made by hand, and I used the magic of the tool to complete the migration of my app.

The application was an experimental COVID-19 stats app, and its code is fully open sourced. You can find it  on GitHub.

#dart #null-safety #flutter

How Dart’s Null Safety Helped Me Augment My Projects
1.60 GEEK