Flutter环境搭建这里只介绍在macOS中Flutter的环境搭建,如需了解windows下的Flutter开发环境搭建请查看https://book.flutterchina.club/chapter1/install_flutter.html
系统要求
获取Flutter SDK
运行flutter doctor
Flutter分支切换
设置编辑器
系统要求
操作系统: macOS (64-bit)
磁盘空间: 700 MB (不包括Xcode或Android Studio的磁盘空间).
工具: Flutter 依赖下面这些命令行工具.
bash, mkdir, rm, git, curl, unzip, which
获取SDK
1、配置国内镜像
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
2、安装包下载
官网地址:https://flutter.io/sdk-archive/#macos
另外:可以直接使用git clone -b dev https://github.com/flutter/flutter.git,来获取flutter SDK,通过此方式获取SDK可以忽略第三步。
具体请参考 https://flutter.dev/community/china
3、解压安装包
使用unzip命令
cd ~/你想安装的目录
unzip ~/Downloads/flutter_xxx.zip
4、添加flutter相关工具到path
export PATH=`pwd`/flutter/bin:$PATH
最终
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export FULLTER_HOME=/Users/lc/flutter
export PATH=$PATH:$FULLTER_HOME/bin:$PATH
flutter doctor
在Flutter命令行运行如下命令来查看是否还需要安装其它依赖,如果需要请安装它们,如下是一个例子:
lvchaodeMacBook-Pro:~ lc$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.13.6 17G5019, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✗] 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 with
Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
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
[!] IntelliJ IDEA Community Edition (version 2018.2.4)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (1 available)
! Doctor found issues in 2 categories.
Flutter分支
1、使用flutter channel查看Flutter分支
lvchaodeMacBook-Pro:~ lc$ flutter channel
Flutter channels:
beta
dev
master
* stable
2、使用 flutter channel xx切换分支
lvchaodeMacBook-Pro:~ lc$ flutter channel beta
Switching to flutter channel 'beta'...
git: From https://github.com/flutter/flutter
git: * [new branch] auth_codes -> origin/auth_codes
git: 6ba720a..8bea3fb dev -> origin/dev
git: 0b8403b..404f66d master -> origin/master
git: * [new branch] revert-30873-revert-30414-remove-hover-pressure -> origin/revert-30873-revert-30414-remove-hover-pressure
git: * [new branch] revert-30919-initial_auth_codes -> origin/revert-30919-initial_auth_codes
git: * [new branch] v1.4.9-hotfixes -> origin/v1.4.9-hotfixes
git: * [new tag] v1.4.11 -> v1.4.11
git: * [new tag] v1.4.18 -> v1.4.18
git: * [new tag] v1.4.12 -> v1.4.12
git: * [new tag] v1.4.13 -> v1.4.13
git: * [new tag] v1.4.14 -> v1.4.14
git: * [new tag] v1.4.15 -> v1.4.15
git: * [new tag] v1.4.16 -> v1.4.16
git: * [new tag] v1.4.17 -> v1.4.17
git: Switched to branch 'beta'
git: Your branch is up-to-date with 'origin/beta'.
设置编辑器
1、AndroidStudio
(1)安装AndroidStudio
(2)安装dart插件和flutter插件
Preferences>Plugins 搜索Dart和Flutter这两个插件
(3)新建一个flutter项目
File>New>New Flutter Project