Not so long ago, I had a problem with two projects. One was using version 1.22.6, and the other needed version 2.0.4. So I had a question, how can I use different versions of Flutter for various projects. After searching a bit of information, I came across FVM or Flutter version manager. It’s a simple CLI that is supposed to help in this situation. Let’s move on to the installation.
It is worth noting that before you install the FVM, you need to make sure that Dart is installed. To do this is relatively easy enter the following command:
After making sure that Dart is installed, we can proceed to install the FVM using the command.
> Dart pub global activate FVM
I suggest adding the following lines to the Path environment variable:
It will save you a lot of trouble and time in the future. After a successful FVM installation, let’s double-check the result with the command.
The next step is to install the Flutter version we need. First, we can see what versions are available to us:
> FVM releases
To install the version we like, use the command:
> FVM install <wanted_version>
Or you can specify not a specific version, but say stable, dev, or beta.
When I used FVM install for the first time, I encountered the following problem:
I couldn’t find a solution to this problem for a while until I tried running the command line as an administrator. After that, the problem no longer occurred.
The next step is to choose the correct version for our Flutter project. We can see a list of installed versions with the following command:
> FVM list
To use the version we are interested in, run the command:
> FVM use <wanted_version>
It is worth noting that we have to be in the directory of our project to use this command.
Now we need to configure our IDE to work with the FVM. All we have to do is to choose the path to our Flutter and Dart. Let me show you an example of Intellij Idea. We need to change the paths to Flutter and Dart SDK. The FVM creates a .fvm folder in our project that contains the previously selected Flutter version. For the Flutter SDK, the path is
..\your_project\.fvm\flutter_sdk and for Dart SDK ..\your_project\.fvm\flutter_sdk\bin\cache\dart-sdk.
That’s all. Now you can use different versions of Flutter for various projects and change the SDK at any time. Don’t forget to visit the FVM page on pub dev. There is a lot of helpful information at https://pub.dev/packages/fvm. I hope this article was useful, thanks for your attention.