一、終端在任意文件夾中flutter的命令無效
此時需要配置全局命令,步驟如下:
1.在終端執行
open .bash_profile
打開.bash_profile文件
2.在.bash_profile文件中寫入如下命令
export PATH=/Applications/flutter/bin:$PATH
其中的/Applications/flutter/bin表示你當前放置下載的flutter包的位置下的bin文件
3.然后保存此文件,在終端在執行
source ~/.bash_profile
使命令生效
如此就完成了配置。
二、下載flutter項目中三方包超級慢或者下載不下來的問題,其實就是flutter pub get 命令進行加載包
這是由于pub.dev的服務器在國外,所以我們需要配置國內的鏡像。
具體步驟如下:
1.在終端執行
open .bash_profile
打開.bash_profile文件
2.在.bash_profile文件中寫入如下命令
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
如果此配置依舊慢可以試試上海交通大學的一組鏡像
export PUB_HOSTED_URL=https://dart-pub.mirrors.sjtug.sjtu.edu.cn
export FLUTTER_STORAGE_BASE_URL=https://mirrors.sjtug.sjtu.edu.cn
3.然后保存此文件,在終端在執行
source ~/.bash_profile
使命令生效
三、如果.bash_profiles文件中的配置無效可以試試如下操作
1.在終端執行
open .zshrc
打開. zshrc文件
2.在. zshrc文件中寫入如下命令
source ~/.bash_profile
3.然后保存此文件,在終端在執行
source ~/.zshrc
使命令生效
這是由于mac上如果有.zshrc文件的時候,會優先執行.zshrc文件的配置,所以在此文件保存.bash_profiles的配置即可
四、執行flutter doctor中報錯Xcode的錯,
iOS toolchain - develop for iOS devices
? Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
在終端執行如下命令:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
其中/Applications/Xcode.app代表你的Xcode包的路徑,當然如果你裝了多個Xcode,則你自己該對應Xcode的名稱
五、執行flutter doctor報錯Androrid Studio
則是需要給Androrid Studio安裝Flutter和Dart插件了,
步驟如下:
*1.打開Androrid Studio選擇Configure->Pllugins
*2.在搜索欄搜索Dart,當搜索到結果之后點后右邊的安裝install,當然我這個是安裝過的,顯示的是卸載
*3.同理搜索Flutter,點擊安裝
*4. 都安裝完成之后點擊ok
*5.在終端繼續執行flutter doctor查看是否成功了。
六、當然我們最后一般用VSCode去編寫flutter代碼的
開始使用VSCode的時候我們也需要去安裝Flutter和Dart插件的。
步驟如下:
*1.安裝Dart,在如下圖的擴展中的搜索框搜索Dart,當搜索到之后點擊安裝
*2.安裝Flutter同理Dart
七、使用VSCode改成中文的
VSCode下載:https://code.visualstudio.com/docs/?dv=osx
步驟如下:
*1.command + shift + P,調出命令窗口,在命令窗口中輸入Configure Display Language,點擊
*2.選擇中文(zh-cn),這是重啟VSCode就好了
八、運行flutter項目的時候鎖住了,可以在終端執行如下命令或者刪除flutter包下的lockfile文件, 比如我的flutter就在Applications目錄下的(/Applications/flutter/bin/cache/lockfile )
killall -9 dart