1. 程式人生 > >Flutter環境搭建、執行gallary專案

Flutter環境搭建、執行gallary專案

Flutter環境搭建、執行gallary專案

主體步驟

1、從github clone flutter的sdk,

git clone -b beta https://github.com/flutter/flutter.git

具體步驟參照官方文件。https://flutter.io/get-started/install/

2、配置環境變數
zsh使用者配置~/.zshrc檔案,新增進環境變數。如下所示。
前兩個是國內使用者配置的映象地址,第三個第四個是剛才clone下來的專案的檔案目錄,具體到bin目錄下。

//flutter
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PWD=/Users/XXX/flutter/bin
export PATH="${PWD}:${PATH}"

配置完成之後,重新整理終端。

使用echo $PATH命令檢視環境變數是否配置成功。

3、使用flutter doctor命令來執行Flutter的安裝程式了。這裡貼上我執行完doctor命令之後的診斷資訊,如下所示:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.9.4, on Mac OS X 10.13.6 17G2208, locale en-CN)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.2)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[!] 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
    ✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
        For more info, see https://flutter.io/platform-plugins
      To install:
        brew install cocoapods
        pod setup
[✓] Android Studio (version 3.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.28.2)
[!] Connected devices
    ! No devices available

! Doctor found issues in 4 categories.

總結一下,關鍵資訊如下:

  • Flutter的版本號及相關資訊。
  • Android工具鏈資訊,Android SDK 版本等。
  • IOS工具鏈資訊,xcode等相關工具需要安裝。
  • Android Studio相關資訊,需要安裝Flutter和Dart外掛。
  • VS Code相關資訊。
  • 已連線的裝置資訊:無。

這裡給出的提示很詳細,均提供了對應的解決方式,根據提示去逐步安裝即可。

4、Android Studio外掛安裝失敗。
需要更新Android Studio到最新版,然後再手動安裝Dart和flutter外掛。

  • 去官網下載最新版的Andorid Studio,這裡是3.2.1,下載完成之後覆蓋安裝。
  • 下載與Android Studio相容的Dart外掛。

5、執行程式碼:下載一個IntelliJ,然後開啟專案
專案根目錄為 …/flutter/examples/flutter_gallary
錯誤解決:pubspec.yaml中,版本號不匹配

Running "flutter packages get" in flutter_gallery...            
Because flutter_gallery depends on flutter_driver any from sdk which depends on source_maps 0.10.7, source_maps 0.10.7 is required.
So, because flutter_gallery depends on source_maps 0.10.8, version solving failed.

pub get failed (1)
Process finished with exit code 1

解決方式:切換到beta分支即可。

git checkout -b beta origin/beta

參考

官方文件
github地址
外掛開發,引用外掛報plugin “XXX”is incompatible with this installation
玉剛說