nav font loadernav font loader
Flutter

How to handle different Flutter SDK versions

Introducing Flutter Version Management (FVM), a tool that allows you to have multiple Flutter SDK versions and use them per project.

We share our knowledge and experience in our blog | Somnio Software

by Hairon Chaviano

3 min read · Aug 04, 2022

A common problem

As Flutter Developers, we often face situations where we have multiple projects that use different versions of the SDK. At this point, millions of questions arise: Should I upgrade all projects? Am I wondering if all my packages support that version? Will I break the projects? Is it essential to upgrade all my projects to the latest version?

Answering these questions depends greatly on the context, which is why I'd like to introduce you to a tool that can help you.

FVM to the rescue

Flutter Version Management (FVM) is a tool that allows you to have multiple Flutter SDK versions installed and use them per project. Using this tool, you’ll be able to run any project using any Flutter SDK version.

Installation process

Now we know FVM and what it can do for us, let’s see how to install it.

MacOS and Linux:

Install:

brew tap leoafarias/fvm

brew install fvm

Uninstall:

brew uninstall fvm

brew untap leoafarias/fvm

Activate:

dart pub global activate fvm

Windows:

Install:

choco install fvm

Activate:

dart pub global activate fvm

Now we have the FVM installed, you probably want to add it to the .gitignore file in order to avoid upload unnecessary files to your repo, so to do that add the following paths to your .gitignore: .fvm/flutter_sdk

.fvm/fvm_config.json

Using FVM on my project

Once the FVM is ready to use, we need to set the Flutter SDK version that we want to use for the project. You need to move to your project /lib path using the terminal and write the command:

fvm use <flutter_sdk_version>

I really recommend,  based on my and my teammates experiences, quitting your code editor or IDE after setting the Flutter SDK version just to avoid conflicts with previous versions.

And that’s all, folks! Now every Flutter command that you need to execute you’ll need to add fvm word at the beginning, e.g: fvm flutter pub get.

Useful commands

Here I share a list of useful commands:

  1. List of installed versions: fvm list
  2. Change version: fvm use <new_sdk_version>
  3. Install version: fvm install <new_sdk_version>
  4. Remove version: fvm remove <flutter_sdk_version>
  5. List of available releases to install: fvm releases

Configure global version

Are you the kind of person that hate write fvm on each Flutter command?

Don’t worry. All you need to do is configure the global version. By doing this, you can have the default Flutter version in your machine, but keep the dynamic switching. It allows you not to make any changes on how you currently use Flutter, but with faster switching and version caching.

To accomplish this, you’ll need to run the following command:

fvm global <flutter_sdk_version>

After this step, you don’t need to use fvm word more on your Flutter commands… just to change the Flutter SDK version :)

Using FVM with flavors

You can also use different Flutter SDK versions for different project environments or release type better knows as flavors, let’s see how to configure the flavors for FVM.

Go to the .fvm/fvm_config.json path and by default you will see something like this:

Now you only need to add your flavors inside the “flavors” object like this:

More useful commands… for flavors
  1. To choose a specific version for a flavor: fvm use <new_sdk_version> --flavor <flavor_name>
  2. To switch between flavors: fvm flavor <flavor_name>
  3. To see the list of flavors: fvm flavor

Conclusions

For us (Flutter developers), FVM comes in handy. In general, it is always recommended to keep your project updated if you are involved in several projects or want to use a different SDK version than the one you already have. However, there are times when you can't do it, and using FVM is the best way to avoid the questions we already asked at the beginning.


by Hairon Chaviano

3 min read · Aug 04, 2022

Hairon Chaviano is a Software Developer at Somnio Software. Hairon is a technology enthusiast, originally from Cuba and now living in Uruguay since 2019.

Software development
Mobile app development

Let’s create successful apps together!

ˑ
Select...