- 安裝獨立的
dart
環(huán)境
官方安裝方法:https://dart.dev/get-dart
或者下載包:https://dart.dev/tools/sdk/archive
brew tap dart-lang/dart
brew install dart
- 更新
dart
版本:
brew upgrade dart
- 重新安裝
dart
:
brew reinstall dart
- 查看當前dart版本:
$ dart --version
Dart SDK version: 2.13.1 (stable) (Fri May 21 12:45:36 2021 +0200) on "macos_x64"
- 查看當前安裝的dart信息:
$ brew info dart
dart-lang/dart/dart: stable 2.13.1, HEAD
The Dart SDK
https://dart.dev
Conflicts with:
dart-beta (because dart-beta ships the same binaries)
/usr/local/Cellar/dart/2.13.1 (508 files, 477.8MB) *
Built from source on 2021-05-31 at 09:44:27
From: https://github.com/dart-lang/homebrew-dart/blob/HEAD/dart.rb
==> Options
--HEAD
Install HEAD version
==> Caveats
Please note the path to the Dart SDK:
/usr/local/opt/dart/libexec
- 安裝
fvm
命令:pub global activate fvm
$ pub global activate fvm
Package fvm is currently active at version 2.0.5.
Resolving dependencies... (3.4s)
The package fvm is already activated at newest available version.
To recompile executables, first run `global decativate fvm`.
Installed executable fvm.
Warning: Pub installs executables into $HOME/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, etc.):
export PATH="$PATH":"$HOME/.pub-cache/bin"
Activated fvm 2.0.5.
- 配置
.bash_profile
中添加:
# fvm
export PATH="$PATH":"$HOME/.pub-cache/bin"
使.bash_profile
生效:
source ~/.bash_profile
重啟命令行工具骗村,執(zhí)行fvm
:
$ fvm
Flutter Version Management: A cli to manage Flutter SDK versions.
Usage: fvm <command> [arguments]
Global options:
-h, --help Print this usage information.
--verbose Print verbose output.
--version current version
Available commands:
config Set configuration for FVM
dart Proxies Dart Commands
doctor Shows information about environment, and project configuration.
flavor Switches between different project flavors
flutter Proxies Flutter Commands
global Sets Flutter SDK Version as a global
install Installs Flutter SDK Version
list Lists installed Flutter SDK Versions
releases View all Flutter SDK releases available for install.
remove Removes Flutter SDK Version
spawn Spawns a command on a Flutter version
use Sets Flutter SDK Version you would like to use in a project
Run "fvm help <command>" for more information about a command.
-
fvm
相關(guān)命令
- 配置
fvm
緩存路徑(可選撵儿,默認在用戶目錄下fvm/versions
文件夾):
fvm config --cache-path <CACHE_PATH>
- 查看當前安裝的flutter版本:
$ fvm list
No SDKs have been installed yet. Flutter. SDKs installed outside of fvm
will not be displayed.
- 安裝指定版本的flutter:
$ fvm install 2.2.1
Flutter "2.2.1" is not installed.
Installing version: 2.2.1...
Cloning into '/Users/yuanzhiying/fvm/versions/2.2.1'...
- 刪除指定版本:
$ fvm remove 2.2.0
Removing 2.2.0...
2.2.0 removed.
此時會在用戶目錄下自動創(chuàng)建fvm/versions/2.2.1
文件夾弯菊,如果本地已有flutter
巷疼,可將本地的flutter
拷貝到versions
目錄下咕娄,文件夾改為對應(yīng)的版本名灾杰。當前flutter
版本可以在flutter
根目錄下的version
文件里查看荣茫。
/Users/yuanzhiying/fvm/versions/1.22.6
- 查看已安裝的flutter版本:
$ fvm list
Cache Directory: /Users/yuanzhiying/fvm/versions
2.2.0
1.22.6
- 查看環(huán)境信息和項目配置
FVM Version: 2.0.5
___________________________________________________
FVM config found:
___________________________________________________
Project: info_valley
Directory: /Users/yuanzhiying/mobile_life/info_valley
Version: 1.22.6
Project Flavor: None selected
___________________________________________________
Version is currently cached locally.
Cache Path: /Users/yuanzhiying/fvm/versions/1.22.6
Channel: false
SDK Version: 1.22.6
IDE Links
VSCode: .fvm/flutter_sdk
Android Studio: /Users/yuanzhiying/mobile_life/info_valley/.fvm/flutter_sdk
Configured env paths:
___________________________________________________
Flutter:
Dart:
/usr/local/Cellar/dart/2.13.1/libexec/bin/dart
FVM_HOME:
not set
- 使用對應(yīng)版本的flutter:
切換至項目目錄厂捞,執(zhí)行命令:
$ cd mobile_life/info_valley
$ fvm use 1.22.6
Project now uses Flutter [1.22.6]
HandshakeException: Connection terminated during handshake
查看當前的使用版本:
$ fvm list
Cache Directory: /Users/yuanzhiying/fvm/versions
2.2.0
1.22.6 (active)
項目目錄下會生成一個隱藏文件夾.fvm
image.png
- 配置項目忽略文件.gitignore
.fvm/flutter_sdk
- 項目配置
flutter
路徑
選擇flutter
的sdk
路徑:
image.png
自動生成當前使用的flutter
路徑:
image.png
image.png
重啟Android studio餐屎。
-
flutter
命令的使用
此時執(zhí)行flutter doctor
找不到flutter
命令:
$ flutter doctor
zsh: command not found: flutter
所有flutter
命令前加上fvm
即可:
$ fvm flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel stable, 1.22.6, on macOS 11.3 20E232 darwin-x64, locale zh-Hans-CN)
[?] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[?] Xcode - develop for iOS and macOS (Xcode 12.5)
[?] Android Studio (version 4.2)
[!] Connected device
! Error: 營的iPhone is not connected. Xcode will continue when 營的iPhone is connected. (code -13)
! Doctor found issues in 1 category.
$ fvm flutter pub get
Running "flutter pub get" in info_valley... 1.4s
-
flutter
下dart
命令的使用
所有dart
命令前加上fvm
即可:
$ fvm dart --version
fvm: running Dart from Flutter "1.22.6"
Dart SDK version: 2.10.5 (stable) (Tue Jan 19 13:05:37 2021 +0100) on "macos_x64"
- 便捷使用命令
在.bash_profile
中設(shè)置命令的別名:
# aliases 快捷使用fvm命令
alias flutter="fvm flutter"
alias dart="fvm dart"
使生效:
source ~/.bash_profile
重啟命令行工具檀葛。
$ flutter pub get
Running "flutter pub get" in info_valley... 1.0s
$ dart --version
Running using Flutter version configured in path.
Dart SDK version: 2.13.1 (stable) (Fri May 21 12:45:36 2021 +0200) on "macos_x64"
- 設(shè)置全局默認的flutter版本
$ fvm global 1.22.6
Flutter "1.22.6" has been set as global
However your "flutter" path current points to:
.
to use global Flutter SDK through FVM you should change it to:
/Users/yuanzhiying/fvm/default/bin
此時fvm
目錄下自動生成了一個default
的快捷文件夾。
image.png