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.
Let’s start using fvm
Dart pub global activate fvm
fvm releases.
fvm install {version} eg: fvm install 2.10.1.
fvm list.
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.