With the help of Flutter version manager (FVM) we can use a specific vesion of Flutter for each of our projects.
There are several benefits to this approach:
- It ensures that all people on the project use same version of Flutter.
- If one of your projects is on the stable channel and the other one is on beta channel you would have to switch channel every time. And that command takes a bit time to run. FVM solves this by using two flutter versions.
- If one project is not actively maintained anymore, but client returns with new change request year later. What can happen is that some plugins or code doesn't work anymore with new flutter version, so FVM ensures we can use old version and coordinate version update.
Setup
One person should setup FVM in the project. If the setup is already completed, you can skip to Using FVM.
Setup FVM in project
Follow the official instructions to setup FVM and configure the .fvmrc file.
Only commit the .fvmrc file. The .fvm/ folder should be added to .gitignore:
# FVM Version Cache
.fvm/
Setup FVM on Bitrise
Use the Extract FVM Flutter version Bitrise step to obtain the Flutter version. In the Flutter Install step, set Flutter SDK git repository version to $FVM_FLUTTER_VERSION.
Using FVM
When calling Flutter from the command line, use the fvm prefix:
# instead of writing
flutter pub run build_runner
# use the fvm prefix
fvm flutter pub run build_runner
When using an IDE (Android Studio), change the Flutter SDK path to the one provided by FVM:
Android Studio > Settings... > Language & Frameworks > Flutter
Change the Flutter SDK path to .../project-name/.fvm/flutter_sdk.
Now all your run, debug and other tools will use the Flutter version defined in the .fvmrc file.
IMPORTANT: the IDE setup is per-project, meaning it will have to be done for each project that uses FVM.