FVM: Manage Flutter Versions like A Beast

Flutter Version Management 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.

Features:

  • Configure and use Flutter SDK version per project
  • Ability to install and cache multiple Flutter SDK Versions
  • Fast switch between Flutter channels & versions
  • Dynamic SDK paths for IDE debugging support.
  • Version FVM config with a project for consistency across teams and CI environments.
  • Set global Flutter version across projects

Installing FVM on your machine:

1- First step is to make sure that pub is defined and recognized in your machine global environment variables. To do this you need to Open system terminal and run pub command to find the following output

Make sure that you’re using pub not flutter pub as Flutter SDK contains a different Pub executable file inside the Dart SDK directory . That’s not the directory we need with FVM. If you ran the pub command and only got 'pub' is not recognized as an internal or external command, operable program or batch file that means that pub executable files are not found on the right directory.

To solve this issue you’ll need to navigate to C:\Users\~USERNAME~\AppData\Local\Pub\Cache\bin. Most probably you’ll find the bin directory empty, that’s why you need Copy pub.bat , fvm.bat , dart.exe and snapshots directory from C:\Flutter_SDK_DIR\flutter\bin\cache\dart-sdk\bin into the bin directory in the first path. Now you need to restart CMD and try running pub command again.

2- Now we need to activate the FVM package by running pub global activate fvm

3- Now as FVM is now active on our machine, we need to save its executable path to the system global environment variables. So in your task bar search field type env and Open Edit system environment variables and click on Environment Variables button at the end of the dialog. Check for Path variable and click Edit button. Now you’ll add a new value to the Path variable by clicking New and pasting the following path: C:\Users\~USERNAME~\AppData\Local\Pub\Cache\bin. Save the changes and quit.

Installing your favorite Flutter versions

Now it’s the step where we cache as much Flutter versions as we like for future usage. FVM supports multiple ways to do so. For example, If you want to install the most recent stable version all you need to do is running fvm install stable command. It’s applies on other channels too, so for latest Beta we use fvm install beta command.
FVM also supports installing a certain version by its name. So if you need to install 1.22.5, you’ll run fvm install 1.22.5. Voilla!

After installing all your favorite versions. You can check the full installed (Cached) list by running fvm list. It’s worth mentioning also that you can take a look at all the available Flutter versions by running fvm releases.

Running your projects under FVM

Assigning a flutter version to a specific project now turns a piece of cake. You need to run fvm use <Cached-Flutter-Version> command. This will generate an .fvm directory into your project root directory. I recommend to add this generated directory to your project gitignore as it’s a local configuration directory which no other team member would be interested to pull.

Now if you run fvm list again you should see the project selected version with check mark next to it:

Configuring IDE to use FVM versions

The last step is to letting your IDE (Android Studio/VS Code) know where to get the Flutter SDK from. Usually it’s set to the default Flutter SDK path. Now we’ll replace it with the FVM cached SDK path.

In your generated .fvm directory there’s a flutter_sdk directory which we’ll use its path to be set in the IDE Flutter SDK path now.

Conclusion

FVM is a very powerful tool which provides Flutter developers with a set of productivity features beyond just versions switching. In this article we explored the basic features of it. For a long time versions management was something expensive as we always need to re-download the desired version to replace the existing one, taking into account the download time and the risk to lose internet connection during this process and lose both versions. I’d recommend to check FVM official documentation for more information

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Scroll to Top