Official Doc: fvm | Flutter Version Management
FVM version: 2.2.4
Install the FVM
Choose one of the following installation methods:
- The Dart PUB installation runs directly
dart pub global activate fvm
Copy the code
- Install via Homebrew
brew tap leoafarias/fvm
brew install fvm
Copy the code
Configure environment variables. The following uses ZSH as an example
Vim ~/.zshrc Add the following environment variables
export FVM_HOME="$HOME/.fvm"
Copy the code
Note: the FVM_HOME path is the installation location of Flutter managed by FVM. The default path is the FVM folder in the user directory, which can be customized to your own preference.
Add a domestic mirror to Flutter
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
Copy the code
Note: If you have previously installed Flutter, you need to remove or comment out the previous environment variables associated with Flutter
Install the required version of Flutter via FVM
Use FVM install version or channel
fvm install stable
Copy the code
Apply different versions of Flutter for different projects
Assume that the requirements are stable for project 1 and beta for Project 2
Execute at the root of project 1
fvm use stable
Copy the code
Configure the Flutter environment for Android Studio
- Open project 1 using open Android Studio
- Open Android Studio → Preferences→Languages & Frameworks→Flutter
- Flutter SDK path Select path (… /.fvm/versions/stable)
- Click Apply → OK
- Restart the Android Studio
Configure the Flutter environment of VSCode
- Open settings.jaon (open Settings via command+ Shift + P)
- Add the following code to the file
{
...,
"dart.flutterSdkPath": ".fvm/flutter_sdk",
// Remove .fvm files from search
"search.exclude": {
"**/.fvm": true
},
// Remove from file watching
"files.watcherExclude": {
"**/.fvm": true
}
}
Copy the code
FVM creates a soft connection in the project named.fvm that points to the Flutter applied in step 1, so different projects in VSCode can automatically adapt their own versions of the Flutter
Repeat steps 1 and 2 in item 2
FVM configuration + use is complete.
other
- through
fvm global
The version or channel command can globally specify a Flutter version, used in projects that do not specify a Flutter version. - It is recommended that you configure an alias for FVM FLUTTER in the environment variables to facilitate subsequent use
alias f="fvm flutter"