inqVine

View Original

Managing Flutter Versions with Flutter Version Manager

With the number of version managers for tools such as NPM and Golang, it was only a matter of time before a good one came out for Flutter right?
Welcome FVM!

This tool is the go to in both my personal and mainline projects for managing the version of Flutter you are currently running without the faf of having to keep track of commit hashes and a verbose CI/CD build script. In short, it keeps track of what versions of Flutter you have installed, allows you to install specific versions, and jump between them seamlessly, even on a per project basis if you so choose.

Thank you to the FVM.app team for making sure an obvious but cool plugin.


Why might you want to use this?

Quick introduction on why you should ideally use something like this. Flutter especially suffers from package hell, if you’re bad like me, then you probably started by telling your apps to always build on the latest version on the stable branch, with a minimum set list of dependencies prefixed with ^.

Don’t get me wrong, this is a fantastic place to start, but when you start scaling you application, how do you know the version you tested is the same as the one on the store if you’re working across a team? Especially one where the testers have their own environment and compile the application themselves. Also how do you tell what version stable was when you update to the next stable build without keeping track of the Github commits or using a craft bit of Google.

The answer is quite simple, outsource it. Use a tool which allows you to pin you application to a set version, and then compile uniformly across your team and build servers.


Getting started

FVM should be installed using a version of the Dart SDK independent from the version included with your Flutter installation. It will be important to make sure we have a clean work environment first with just Dart installed and no versions of Flutter. This is because the tool itself uses Dart, so it is a chicken and egg situation if you don’t have a place to start from. Use the below steps to get this running properly.

  • Uninstall any current versions of Flutter fully, including removing any PATH variables set to point to the installation or Dart plugin folders

  • Install a fresh version of Dart. Using Windows, I would recommend installation through chocolately. Alternatively use Brew on Mac or your package manager of choice in a Linux/Unix distribution. This will allow you to use that package manage to keep the separate version of Dart up to date.

  • Verify the Dart installation added a record for its pub cache in your PATH. It should be something like %USER_PROFILE%\AppData\Local\Pub\Cache\bin on Windows.

  • Run dart pub global activate fvm to activate Flutter Version Manager

  • Verify the default Flutter bin folder is added to your PATH after FVM installed. On Windows once again it should be something like %USER_PROFILE%\fvm\default\bin

  • Run fvm releases to get a list of the latest Flutter versions

  • Call fvm install # to install your selected version of Flutter

  • Run fvm global # to set that version of the current version you’re using

And thats it! You can now repeat these steps programmatically in your CI/CD pipeline to pass a version in via build parameters, or simply use it to keep up to date when a new version is available. Either way, it will give you a lot more power over the current version of Flutter you are running.


Useful Tips

  • For the less CLI inclined, try the Flutter Sidekick project to assist you along the way

  • You can call fvm use # to add a version to a project specifically. This is useful if supporting packages which are up to date with beta builds, or builds too old for new features like null safety

  • You can find docker images for specific versions all over the place for your build pipelines. I like to use the Cirrus CI images

  • Add a link to these steps as well as the version recommended in your README.md to make onboarding new staff easier

  • You can use FVM for beta, dev, and even on a per commit basis, not just stable builds

  • Check out Fun with Flutters youtube video if you need a more visual installation walkthrough. Thanks to their team for doing this!

  • Use specific versions of dependencies to keep everything exact when building your project. This should help remove unwanted pubspec.lock changes in your commit list.


Thats all for this article. This tool is used massively in industry but I see a lack of new Flutter users using such tools, so despite their being content already; I feel these tool chains should be better exposed to new Flutter developers to help them get started!

Until next time,

The inqVine team