Version Management in Flutter with FVM

Swaroop Sambhayya
5 min readMay 13, 2021

Introduction

Ever wondered how can I manage different versions of Flutter under a single machine? well we have FVM.

FVM is a simple cli to manage Flutter SDK versions. FVM helps with the need for a consistent app builds by allowing to reference Flutter SDK version used on a per-project basis. It also allows you to have multiple Flutter versions installed to quickly validate and test upcoming Flutter releases with your apps, without waiting for Flutter installation every time.

Things that can done with FVM

  1. Use perticular version of Flutter either by choosing channel stable,dev or beta or by mentioning a fixed version.
  2. Install and cache multiple SDK ersions
  3. Changing SDK path dynamically
  4. Quick switch between channels and versions
  5. Setting a global version across the projects

Installing FVM

Make sure that flutter is installed in your machine and everything is working fine by running following command in you CLI

>flutter doctor

If no issues found then we are good to go! lets install fvm by running following command on CLI

>pub global activate fvm

The above commmand will get all the dependencies and installs fvm globally, So lets make sure whether fvm is installed in our machine and available globally by running following command

>fvm

If everything’s fine you will get a list of available commands used with fvm and a brief description on each command.

In case of Windows, if the CLI is not recognizing fvm or pub as command then we need provide the path of pub which will be like, C:\Users\User_Name\AppData\Roaming\Pub\Cache\bin to PATH variable in Sytem Environment variables.

Using fvm in your projects

Now that we have installed fvm lets see how to use it in our projects by knowing few commands. Lets install a specific version of flutter or channel using fvm. Run following command to know the different versions that you can switch to.

>fvm releases

The above command will give you all the versions that are available to install, after deciding which version or channel you want to install run the below command to install it. For an example let’s install stable and dev versions

>fvm install stable
// This command will install stable version
>fvm install dev
// This command will install dev version

You can also install a fixed version by running

>fvm use 1.22.5

The installations will take some time to download these versions, after installation just run below command

>fvm list

This command will list all the versions that you have installed with fvm.Now that we have installed these versions lets use it in our project, Navigate to your project folder in CLI and run the command

C:\Users\USER_NAME\project_name>fvm use stable
Project now uses Flutter: stable

By running this command, we make project to use the specific version that we want.If there is any problem in running this command please open the cli as administrator and navigate to project folder then re run the command. Cool ! we learnt a lot , now lets learn setting up fvm with our favorite IDE’s Android studio and Visual Studio Code.

Setting up fvm in Android Studio

Now let’s learn setting up fvm in android studio, open the flutter project in the android studio and find .fvm folder

Under .fvm folder there is a folder named flutter_sdk. Copy the absolute path of “flutter_sdk” folder and navigate to File -> Settings -> Language and Frameworks then paste the copied path in Flutter SDK path field as shown below

Click on Apply and go back to terminal either in android studio or the CLI and run command fvm use <specific version> and restart or invalidate cache of android studio. That’s it the selected version will be used in android studio you can change any version you want but one problem in android studio is either you have to invalidate cache or restart every time you change version with fvm.

Setting up fvm in Visual Studio Code

I’m personally a big fan of Visual Studio Code as it is light and has many extensions to develop faster. Let’s see how to set up fvm in visual studio code.

Steps

  1. Open your Flutter project in Visual Studio Code and find .fvm folder which will be at root, under .fvm copy the absolute path of flutter_sdk folder.
  2. Open settings.json from View -> Comand Palette -> search “Preferences: Open Settings (JSON)” and click on the it.

3. Add “dart.flutterSdkPaths”: [“.fvm/flutter_sdk”] at the end of JSON file and save it.

4. Now if we re-open command palette and search for Flutter: Change SDK and tap on search result you will get a different versions of Flutter that is currently installed with fvm. Select the version that you want to change instantly.

In this image we have two versions 1.22.5 and 2.0.1

That’s it, the project and IDE will be setup for using the selected version! .

Conclusion

You have done a great job reaching till here 🎉🎉! In this article we have learnt how to install fvm, configure, use it in different projects and configure fvm for Android Studio and Visual Studio. I hope you guys learnt something from this article!

Thank you 😀

--

--