A Brief Introduction to Flutter Version Management
Introduction
Flutter Version Management (or FVM) is a simple CLI to manage different Flutter versions on a per-project basis. This means that we can now define a specific Flutter version for each project.
Why do you need FVM?
When working on Flutter projects you may need to switch between different SDK versions to validate and test upcoming Flutter releases with your apps, which is very tedious and time-consuming. This is where FVM comes to the rescue.
FVM allows you to have multiple Flutter versions installed on your local machine to quickly test your app against the upcoming new Flutter releases without waiting for Flutter installation every time. It also allows you to manage multiple channels
and releases
, and caches these versions locally, so you don’t have to wait for a full setup every time you want to switch versions.
Not only that, but you can also grab versions by a specific release, i.e. v2.0.0
or v2.1.0–12.1.pre
in case you have projects on different Flutter SDK versions that you do not want to upgrade.
How to use
Before we install/activate FVM make sure that Dart
is installed on your local machine by typing in the following command:
$ dart
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:
$ pub global activate fvm
⚠️ Do not activate FVM using
flutter pub global activate
if you plan on using the--global
flag. Only activate FVM usingpub global activate fvm
.
List Flutter Releases
Before you download and install any Flutter release, you can list them all including the current version for dev
, beta
and stable
channels by typing in the following command.
$ fvm releases
Install an SDK Version
FVM gives you the ability to install many Flutter releases or channels. Use stable
to install the Stable channel and v2.0.3
or 1.17.0-dev.3.1
to install the release. --skip-setup
will skip Flutter setup after install.
$ fvm install stable or fvm install 2.0.3
Project Config SDK Version
If you configured your project to use a specific version, run install
without any arguments will install the proper version.
$ fvm install
List Installed Versions
You can also list all the installed versions on your machine by typing in the following command. This command will also output where FVM stores the SDK versions.
$ fvm list
Remove a SDK Version
Using the remove command will uninstall the SDK version locally, this will impact any projects that depend on that version of the SDK.
$ fvm remove <version>
Upgrade the current SDK Version
To upgrade currently used Flutter SDK version (e.g. stable
) you should call the Flutter SDK command as you would normally do in case of typical Flutter installation. See more in the section Running Flutter SDK commands.
$ fvm flutter upgrade
Configure Your IDE
In some situations you might have to restart your IDE and the Flutter debugger to make sure it uses the new version. Below are some details on how you can configure your IDE.
Android Studio
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 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.
VSCode
Add the following to your settings.json
. This will list all Flutter SDKs installed when using Flutter: Change SDK
. Use fvm list
to show you the path to the versions.
List all versions installed by FVM
You can see all the versions installed by FVM in VS Code by just providing path to versions
directory:
{
"dart.flutterSdkPaths": ["/Users/usr/fvm/versions"]
}
Alternatively, you can specify only selected versions. The following snippet will cause VS Code to show only stable
and dev
versions of Flutter.
{
"dart.flutterSdkPaths": [
"/Users/usr/fvm/versions/stable",
"/Users/usr/fvm/versions/dev"
]
}
To change current Flutter version open a project and select Flutter: Change SDK
in the command palette. You should see all the versions as depicted in the following screenshot.
You can also add the version symlink for dynamic switch
{
"dart.flutterSdkPaths": [".fvm/flutter_sdk"]
}
Remove the flutter sdk from search to make things easier
{
"search.exclude": {
"**/.fvm": true
},
}
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’s it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.