Flutter Version Management : Easiest way to manage multiple Flutter SDK version through simple CLI

Introduction

After the initial release of flutter back in 2017, it has gain massive response from the developers across the world and its becoming popular across the communities like GitHub, Stack-overflow, Reddit, etc. One of the major feature of flutter is you can build desktop, web and mobile apps with single codebase. But sadly some of the support for web and desktop apps are only available in dev/master branch of flutter. As a developer you might be working with stable branch but you also wanted to try new features from dev, master or other branches, in such cases how do you manage the different versions of flutter from different branches ? In such scenarios Flutter Version Management (FVM) comes in handy. So In this blog we are going to learn how we can setup multiple Flutter SDK in out local machine.

Although we believe you already have Flutter Development environment setup, just in case if you have not, Follow this Flutter Installation Guide. Otherwise, skip this and follow on.

Get started

So basically before jumping in let’s clear out the concept about what FVM actually is and why and when you should use it ?

What is FVM in brief ?

A simple CLI tool to configure Flutter SDK individually. Which means you can configure Flutter SDK in individual project according to your needs.

Why to use FVM ?

If you are working with Flutter projects that might require different SDK in such case you need switch between different SDK versions to validate and test upcoming Flutter releases with your apps, which is very tedious and time-consuming. In such scenarios FVM comes to the rescue and save you.

Features of FVM

  • Easily configure and use desired Flutter SDK version in specific project
  • Easy installation and caching of multiple Flutter SDK Versions in local machine
  • Fast and easy way to switch between Flutter channels & versions
  • Setup dynamic SDK paths for IDE with debugging support.
  • Version FVM config with a project for consistency across teams and CI environments.
  • Set global Flutter version across projects

Installation

To activate FVM in your local machine run the command below:

> pub global activate fvm

If you are having difficulties with running dart script you can refer to official docs here.

To view all the possible commands of FVM run :

> fvm help

List all Flutter Releases:

> fvm releases

After running the command above it will display all the available Flutter SDK including from Dev, beta, and stable channel.

Install and cache a SDK Version :

As FVM gives you ability to install and cache different SDK releases or SDK from different channels. From the above command you can look at all the releases of flutter in different channels, and pick the one you want to install.

To install channel specific SDK run :

> fvm install dev

You can replace the dev with your desired SDK channel.

To install specific release from a channel run :

> fvm install 1.22.6

Similarly, you can replace the1.22.6 with your desired channel of SDK version.

To view all the installed SDK run :

> fvm list

To configure a SDK as global :

> fvm global {version}

You can set the default Flutter version in your machine but still, perform the dynamic switching. It allows you not to make any changes on how you currently use Flutter but benefit from faster switching and version caching. Run fvm list to view which release is configured as global to confirm.

Configuration

Configure SDK in individual project:

To install specific SDK version in your project, navigate to your project folder through terminal or open terminal in your IDE and run :

> fvm install {your_desired_version}

Configure SDK path in IDE :

FVM will create a relative symlink in your project from .fvm/flutter_sdk to the cache of the selected version. Add it to your .gitignore , so that you don’t push it to your repository .

Configure in Visual Studio Code :

Inside your .vscode/settings.json file add the following line of code to remove the flutter SDK from search to make things easier :

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

In your VS Code you can see all the versions installed by FVM by just providing path to versions directory as below :

{
  "dart.flutterSdkPaths": ["/Users/usr/fvm/versions"]
}

Also if you want to display only specific selected versions only. Insert the following snippet to allow VS Code to show only stable and dev versions of Flutter or you can replace stable and dev with your preferred release/version of SDK.

{
  "dart.flutterSdkPaths": [
    "/Users/usr/fvm/versions/stable",
    "/Users/usr/fvm/versions/dev"
  ]
}

Alternatively, if you want to use the specific version for your project which you installed using fvm install {version} command insert the snippet below :

"dart.flutterSdkPath": ".fvm/flutter_sdk"

Configure in Android Studio :

  • Go to Languages & Frameworks > Flutter or search for Flutter and change Flutter SDK path.
  • Copy the absolute path of fvm symbolic link in your root project directory. Example: /absolute-project-path/.fvm/flutter_sdk
  • Apply the changes.
  • Restart Android Studio to see the new settings applied.

If you want to ignore the Flutter SDK root directory within Android Studio you can add the following to .idea/workspace.xml.

<component name="VcsManagerConfiguration">
  <ignored-roots>
    <path value="$PROJECT_DIR$/.fvm/flutter_sdk" />
  </ignored-roots>
...

Bonus Tips :

If you are having issues with installation with the CLI you can use Flutter Sidekick for installing and using FVM. Sidekick is an app that provides a simple desktop interface to tools that enhance Flutter development experience to make it even more delightful. Currently it is in beta release and supports linux, windows, macOS.

References and useful resources :

Below are the useful resources from where i took reference to write this article :

  • Checkout the official documentation for FVM.
  • Download and install the Flutter SIdekick from here.

👨‍💻👨‍💻 Thank You for reading this article 👨‍💻👨‍💻

Tech enthusiastic guy fluttering with dart. Busy with developing apps and websites but somehow manages to contribute to communities. Software Engineering Graduate 👨‍🎓.