Code Swifters

    Multiple Flutter Versions On A Single Machine

what will happen if you are running flutter on version 2.0.6 but you got a project which is running on version 2.10.3. I got into the same situation a day before, I was trying to download flutter 2.10.3 but then I did some research and got to know about FVM.

What is FVM?

Flutter Version Management (or FVM) is a simple command-line interface for managing several Flutter versions per project. As a result, we can now specify a different Flutter version for each project.

Why do we need a tool like FVM?

Sometimes what happens is, just like what happens to me, it may happen to you that you may need different versions of flutter for different projects or verify and test forthcoming Flutter releases with your apps. This is where this tool shines.

The beauty of Flutter version management(FVM) is that it allows you to have multiple flutter versions on a single machine without worrying about path setup and all other frustrating stuff. By using FVM we can immediately test apps against new Flutter releases without having to wait for them to be installed. We can also manage numerous channels and releases. FVM basically caches these versions locally so you don’t have to reinstall everything every time you want to switch versions.

How To Use?

There are a few ways to install FVM. First of all, make sure that Dart is installed on your machine by typing in the following command:

harisatiq@Hariss-MacBook-Air ~ % dart

The output of the above command

Once we know that Dart is installed, the next step is to activate FVM. Open your terminal and type in the following command to activate FVM:

There are two types of installations for FVM:

1. Standalone (Recommended)

1. For MacOS:

For macOS write the following commands

brew tap leoafarias/fvm
brew install fvm

2. For Windows:

To install fvm , run the following command from the command line or from PowerShell:

choco install fvm

2. Pub package

You are able to also install FVM as a pub package.

However, if you plan on using FVM to manage your global Flutter install we recommend installing as a standalone. Run the following command on your Windows / macOS:

dart pub global activate fvm

Some Important Commands:

  1. fvm releases: View all Flutter SDK releases available for installation.

2. fvm list: Lists installed Flutter SDK Versions. Will also print the cache directory used by FVM.

3. fvm install: Sets Flutter SDK Version you would like to use in a project. If the version does not exist it will ask if you want to install it.

4. fvm use: Sets Flutter SDK Version you would like to use in a project. If the version does not exist it will ask if you want to install it.
fvm use {version}

Option:
-h, — help Print this usage information.
-f, — force Skips Flutter project checks.
-p, — pin Pins latest release channel instead of the channel itself.
— flavor Sets version for a project flavor

5. fvm remove: Removes Flutter SDK Version. Will impact any projects that depend on that version of the SDK.

fvm remove {version}

Option:
-h, — help Print this usage information.
— force Skips version global check.

Copy the absolute path of FVM symbolic link in your root project directory.Example: /absolute/path-to-your-project/.fvm/flutter_sdk

In the Android Studio menu open Languages & Frameworks -> Flutter or search for Flutter and change the Flutter SDK path. Apply the changes. You now can Run and Debug with the selected versions of Flutter. Restart Android Studio to see the new settings applied.

Useful Resources:

You should check the examples provided by the FVM package on their github page. Also, their new app with GUI which you can find here.

That concludes this post; if you like it, please show your support by clapping 👏 as many times as you can, leaving comments, and sharing it with your friends.