FVM — use different versions of flutter seamlessly

Abdullah Al Sayeed
7 min readSep 16, 2023

--

You are working on a flutter project(let’s call it serious_project) that uses version 3.7.3, but there is a new practice project(and name it practice_project) where you want to use the latest stable version. You could update the flutter that is installed on your machine, but that could lead to some dependency conflicts with the packages you are using in your serious project. You have to manually resolve those conflicts by updating some portion of the code. You could still update to latest flutter version, done the practice project then again downgrade to 3.7.3 , to continue with your serious project.

You could do many things that you simply don’t want to. For example, here upgrading and downgrading is not only a very hectic approach, it is also very bad one. What will you even do if you have to work on both project frequently? Will you keep upgrading and downgrading? I bet not.

Wouldn't it be easy(and more realistic) to be able to install and use multiple version of flutter at once? Just like venv or pyenv in python?

It definitely would, and there is actually something like this!

This article is also published in Bangla

FVM

Say Hi to FVM, which stand for Flutter Version Manager. Self explanatory to what it’s name says. It lets the user use multiple version of flutter simultaneously in your machine. Even more, it lets you use multiple channels and flavors. It lets you use a specific version as a global version or a per project version. It is very very helpful to maintain different version for different projects. It is also helpful if you want to just give a try to the latest version or a different channel before actually upgrading to it. It is that helpful, and guess what? it is more than that easy to use!

But before going to install it, lets see what motivates the FVM team to bring it to light-

Motivation

  • We need to have more than one Flutter SDK at a time.
  • Testing new SDK features requires switching between Channels.
  • The switch between channels is slow and requires reinstalling every time.
  • No way of keeping track of the latest working/used version of the SDK in an app.
  • Major Flutter updates require migration of all Flutter apps in the machine.
  • Inconsistent development environments between other devs in the team.

Installation

There are two ways you can install fvm(from now we will call it with all lowercase).

  1. Standalone: This way you use fvm to manage your global flutter versions. However, we are not going to follow this approach. We will be following the recommended approach. In case you are curious, take a look at the steps in docs
  2. Pub package: FVM recommends to install Flutter SDK manually, which will be the main version of Flutter across your machine. Then use fvm to manage versions per project. Let’s go!

Assuming you have flutter SDK already installed, it is as easy as installing any pub packages. Just open the console and cast the spell!

dart pub global activate fvm

I already have it installed. So your output could be a little different.

That’s it! Now you can use fvm command to unleash many things!

Let’s play around with the commands.

you can proxy any flutter command by just adding fvm before it. For example, fvm flutter pub get.

How cool is that?

List all installed versions

First, you want to see how many flutter version you have already installed, right? lets do it

fvm list

I have these two versions installed. Probably you have none, since you have not installed yet. Lets go towards this.

Check the available releases

Now you want to install a flutter version. But which one? most probably the latest one. But what is latest version? You can go to the official website to check it, or even better, you can type this command

fvm releases

See? It shows from the latest version to all the way back to the first release, with date, year, version no and channels(stable or beta).

WOW! I no longer need to go to check the website(unless I want to see the release notes).

Install a specific version

Now you have seen all the ancestors of flutter family, and you want install the younger one, 3.13.4. How? just a command I say!

To install a specific version of flutter, fire up the console, type fvm install <version-no> and hit enter.

fvm install 3.13.4

Well, it’s installed! Lets check it.

Remove a specific version

You can have as many version as you wish, but probably you don’t want to eat all your disk space in this way. So? remove unused versions. For example, you may no longer need 2.10.5. So, say bye.

again, just a command I say!

fvm remove 2.10.5

With just it, 2.10.5 is gone(only from your machine. and you can definitely install again if needed. So no need be nostalgic. We have things to do.)

Set a global flutter version

You have installed multiple flutter version. Now you want to set one of them as global, or say, default version. How do you do that?

Simply declare that version as global with the following command. That’s it.

fvm global <version-no>

Here I have declared the latest one as default. Now if I create a new flutter project with fvm flutter create command(you can proxy any flutter command with fvm, remember?), the project will take the default or global version.

Configure specific version for a project

But you want to specifically select a particular version for a project. Perhaps you may want to change the version later. How?

fvm use

you just go to the root directory of your project, open the console, and give the command

fvm use <version-no>

Here we use 3.7.3 version for our serious project. That’s it?

Not yet. We have some tiny but important things to do. Lets understand what this command does.

It will create a .fvm/ directory in the root of the project. If you take a closer look inside, we have a fvm_config_json file, and a flutter_sdk/ directory. This directory is actually a copy of the selected version in our main fvm directory. Now if we set this directory location in our Editor/IDE’s Fluter sdk path, it will always remain same even the contents inside will be changed if we use a different version later.

But before that, we need add this flutter_sdk/ directory to .gitignore, because it has lots of file in it which we don’t want to include in our git commit or push. However we want to include the config_json file, just to know and let others know which version is being used.

.fvm/flutter_sdk

Now, we have to configure our favorite IDE so that it points to this flutter_sdk/ directory as it’s sdk path.

Enough talk, lets do it.

VS Code

just create a .vscode/ directory in the root of your project, create a settings.json file and add the following content in it

{
"dart.flutterSdkPath": ".fvm/flutter_sdk",
// Remove .fvm files from search
"search.exclude": {
"**/.fvm": true
},
// Remove from file watching
"files.watcherExclude": {
"**/.fvm": true
}
}

As simple as that.

Android studio

for android studio it’s a something different, but still very easy. Lets say you want to use 3.13.4 for your practice_project. First give fvm use command as before

Now on top left of the IDE, click file>Settings…>Languages & Frameworks> Flutter

Now copy the exact path of the ./fvm/flutter_sdk/ directory of your project, and set it in your Flutter SDK path and click save.

We are done with the configuration.

fvm doctor

Now before we opt out, we have a fvm doctor command similar to flutter doctor, it shows many information of the project, including the version that is being used in the project. I find it difficult to get the used version with other ways before. Thanks again to fvm!

Conclusion

There are many other things you can do with fvm, for example project flavors, custom flutter versions, install specific revision or may be releasing to multiple channels. FVM team has all that covered. But may be that’s too many for you for now, because we will pretty much need what we have covered in our day to day life. And you can always go to the official docs for what is not covered. This article is just to get up and running with fvm.

That’s all for this article. To get latest update, follow me on LinkedIn. We will meet in another article insha Allah.

Till then- stay happy, keep learning and keep sharing knowledge.

--

--