Shifting to null safety with version management

Hello developers!

There’s no doubt that Flutter is one of the friendliest and most exciting programming languages out there. Which is why, Flutter is also placed second in the “Most loved technology- other frameworks and libraries” category in the Stack Overflow Survey 2021. Being a Flutter developer myself, I can say that it is the most effective cross-platform framework out there. It combines simplicity of development with native performance while preserving a consistent aesthetic appearance across platforms.

But have you found difficulties in changing the environment or using different versions on different projects?

Converting the old codes to null safety or maintaining the older codes as it is and using null safety [versions after dart 2.12 and flutter 2.0] on newer projects might be hastleful for you as well. You must also have faced the problem of syntactic change on the package while updating the versions and package.

I did too.

So, in this blog i will try to solve those problems by talking about the solution that’s already there and many of you might not have heard or felt difficulties to implement it.

There is a package named fvm. fvm is a simple cli to manage Flutter SDK versions. It helps with the need for consistent app builds by allowing the reference flutter SDK version used on a pre-project basis.

Using the fvm package and updating dart to null safety following some simple steps, I think you will be able to solve all those problems. There are certain steps that I will cover later.

Image from Morioh.com

Let’s start using fvm

  • You can install all the package using
 Dart pub global activate fvm
  • In order to view all Flutter SDK releases available for install
fvm releases.
  • To install Flutter SDK version
 fvm install {version} eg: fvm install 2.10.1.
  • To list installed Flutter SDK version
fvm list.
  • To use particular available installed versions
fvm use {version} eg; fvm use 2.10.1.

Using all these commands you will now be able to use the particular version of Flutter. You can also take a look at different configuration and other advanced features that fvm provides here.

Since the Flutter version has been managed, now you can start migrating the dart to null safety.

In order to see the difference between the latest version and the used version of package

fvm flutter pub outdated fvm flutter pub outdated-mode= null safety

To upgrade all the packages to the latest versions

 Flutter pub upgrade- major- versions

All the packages are now updated to the latest available version. You can delete the android/ios folder if any conflict arrives and use

flutter create .

This will recreate those folders.

Now, the final step is to change the dart version to null safety, use

dart migrate 

for this purpose.

A link will be sent to your editor.

Click on it and press Apply migration. The project is now ready. You can use any version of flutter and either convert the project to null safety or use older version before it.

You’re welcome.

Prayash Koirala, Frontend Developer at RARA Labs

Mr. Prayash Koirala is a frontend Developer at RARA Labs, who’s been building path on being Tech entrepreneur with interest in product and business development.
Subject of interest #frontend, #flutter, #data, #stock-market, #real-estate,

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Essential SQL Commands Cheat Sheet for Beginners

The Essential SQL Commands Cheat Sheet for Beginners

AWS Control Tower By Example: Part 2

This is why I don’t work remote

Testing with Capybara the Basics

How to use multiple users with git

Docker: Learn and Practice, Part 1

5 useful Android Studio features you might not know

Snowflake fundamental & comparing with other cloud services

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rara Labs

Rara Labs

More from Medium

A breezy three mile walk

Patch 2.1

Small tan and white dog, view from behind, in the lower centre of the image, in a field of long, green grass, with fields, hedges, trees, and blue sky in the background.

My Final Project Brainstorming Session