Flutter 配置

下载SDK

SDK下载地址
对应下载合适的平台即可,可能由于网速等原因,下载详细未显示,所以我用的是直接git clone。

1
git clone -b master https://github.com/flutter/flutter.git

配置环境变量

1
$ open .bash_profile

在.bash_profile中添加flutter的path

1
2
#flutter
export PATH=/Users/xxxxxxx/flutter/bin:$PATH

更新环境配置

1
2
$ source .bash_profile
$ echo $PATH

执行flutter doctor或flutter –version命令来查看是否还需要安装其它依赖。

1
2
3
4
5
6
7
8
9
Downloading Dart SDK from Flutter engine d1dcd1848633c5764e23313823445cbcba451a59...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:39 --:--:-- 0
curl: (56) SSLRead() return error -9806

Failed to retrieve the Dart SDK from: https://storage.googleapis.com/flutter_infra/flutter/d1dcd1848633c5764e23313823445cbcba451a59/dart-sdk-darwin-x64.zip
If you're located in China, please see this page:
https://flutter.dev/community/china

解决方式:由于在国内访问Flutter有时可能会受到限制,Flutter官方为中国开发者搭建了临时镜像,大家可以将如下环境变量加入到用户环境变量中

1
2
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

正常下载如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
chenyulong01deMacBook-Pro:flutter chenyulong01$ flutter doctor
Downloading Dart SDK from Flutter engine d1dcd1848633c5764e23313823445cbcba451a59...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 120M 100 120M 0 0 655k 0 0:03:07 0:03:07 --:--:-- 656k
Building flutter tool...

╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool anonymously reports feature usage statistics and crash ║
║ reports to Google in order to help Google contribute improvements to ║
║ Flutter over time. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://www.google.com/intl/en/policies/privacy/ ║
║ ║
║ Use "flutter config --no-analytics" to disable analytics and crash ║
║ reporting. ║
╚════════════════════════════════════════════════════════════════════════════╝


Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure
you trust this source!
Downloading Material fonts... 2.8s
Downloading android-arm-profile/darwin-x64 tools... 4.5s
Downloading android-arm-release/darwin-x64 tools... 3.6s
Downloading android-arm64-profile/darwin-x64 tools... 4.6s
Downloading android-arm64-release/darwin-x64 tools... 3.8s
Downloading android-x86 tools... 24.8s
Downloading android-x64 tools... 25.9s
Downloading android-arm tools... 11.6s
Download failed -- attempting retry 1 in 1 second...
Downloading android-arm-profile tools... 9.1s
Downloading android-arm-release tools... 6.0s
Downloading android-arm64 tools... 12.3s
Downloading android-arm64-profile tools... 7.8s
Downloading android-arm64-release tools... 6.1s
Downloading Gradle Wrapper... 0.2s
Downloading package sky_engine... 1.4s
Downloading common tools... 15.0s
Downloading common tools... 15.1s
Downloading darwin-x64 tools... 49.2s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.8.2-pre.56, on Mac OS X 10.12.6 16G29, locale
zh-Hans-CN)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✗] Xcode - develop for iOS and macOS
✗ 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
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
brew install cocoapods
pod setup
[✗] iOS tools - develop for iOS devices
✗ 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
[✓] Chrome - develop for the web
[!] Android Studio (version 3.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (3 available)

! Doctor found issues in 3 categories.
chenyulong01deMacBook-Pro:flutter chenyulong01$

更新flutter及其依赖

更新Flutter

更新Dart及其他依赖

AS Flutter插件安装配置

安装

配置SDK

参考资料

Flutter中文网
Flutter官方事例