[TOC]
# 加速 Flutter
Flutter 在中国的官网:https://flutter.cn。
如果您要使用[安装包](https://flutter.io/sdk-archive/)安装Flutter,则可以使用受信任的镜像替换原始URL的域以加快速度。例如:
* 原始网址:https://storage.googleapis.com
* 镜像网址:https://storage.flutter-io.cn
您需要设置这两个**环境变量**
```
PUB_HOSTED_URL :https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL :https://storage.flutter-io.cn
```
来升级Flutter并使用中国的pub 包存储库。请按照以下说明操作。
window:自行设置环境变量。
mac和linux 为例:
```
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
git clone -b dev https://github.com/flutter/flutter.git
export PATH="$PWD/flutter/bin:$PATH"
cd ./flutter
flutter doctor
```
## 其他镜像站点
Shanghai Jiaotong University Linux User Group
```
FLUTTER_STORAGE_BASE_URL: https://mirrors.sjtug.sjtu.edu.cn/
PUB_HOSTED_URL: https://dart-pub.mirrors.sjtug.sjtu.edu.cn/
```
## 安装 Flutter
使用 `scoop` 安装:
```
scoop search flutter // 搜索 flutter
'extras' bucket:
flutter (1.12.13-hotfix.9)
scoop install flutter //安装 flutter
```
关于scoop 的 extras 中的 flutter 会下载 adb 和 sdk 等,比较麻烦,所以可以把 下面内容存为 `flutter-bc.json ` 放置到:"`...\scoop\buckets\extras`" 中,安装 `scoop install flutter-bc`
```
{
"homepage": "https://flutter.io/",
"version": "0.11.3",
"license": "https://github.com/flutter/flutter/blob/master/LICENSE",
"url":["https://storage.flutter-io.cn/flutter_infra/releases/beta/windows/flutter_windows_v0.11.3-beta.zip"],
"extract_dir": "flutter",
"description": "Flutter is Google mobile app SDK for crafting high-quality native interfaces on iOS and Android in record time. This is the beta version, since Flutter wasn't officially 'released' yet.",
"env_add_path": "bin\\cache\\dart-sdk",
"bin": [
"bin\\flutter.bat"
],
"checkver": {
"url": "https://github.com/flutter/flutter/wiki/Changelog",
"re": "Changes in v([\\d.]+)\\s.*beta.*"
},
"autoupdate": {
"url":"https://storage.flutter-io.cn/flutter_infra/releases/beta/windows/flutter_windows_v$version-beta.zip"
},
"suggest": {
"Visual Studio Code with Flutter Extension": [
"vscode",
"vscode-portable"
]
},
"notes": [
"Flutter has been successfully installed and put in your PATH.",
"If using Visual Studio Code, don't forget to install the Flutter Extension!",
"Then connect an Android Phone and start coding :-)"
]
}
```
Dart SDK 和 Flutter 捆绑在一起,没必要 单独去安装 Dart
## 检测环境
```
flutter doctor //检测是否需要安装任何依赖项
```
如果你选择了使用 IDE ,你会在 `flutter doctor` 的输出看到, IntelliJ IDEA , Android Studio 和 VS Code 有可用插件。参阅[编译器设置](http://doc.flutter-dev.cn/get-started/editor/)获取安装 Flutter 和 Dart 插件的步骤。
## 基本命令
`flutter --version` 显示当前flutter 和 dart版本
`flutter config --no-analytics` 要禁用 功能使用情况,请在终端输入
`flutter config` 要显示当前设置可以输入
# Pub 镜像安装
[https://pub.flutter-io.cn/](https://pub.flutter-io.cn/)
[Pub](https://pub.dartlang.org/) 是 Dart 官方的包管理器。[Flutter](https://flutter.dev/)也基于 Dart 并且可以使用大部分 Pub 中的 库。
如果希望通过 TUNA 的 pub 镜像安装软件,只需要设置 [PUB_HOSTED_URL](https://www.dartlang.org/tools/pub/environment-variables) 这个环境变量指向 [https://mirrors.tuna.tsinghua...](https://mirrors.tuna.tsinghua.edu.cn/dart-pub/) 即可。
以 bash 为例,临时使用 TUNA 的镜像来安装依赖:
~~~
$ export PUB_HOSTED_URL="https://mirrors.tuna.tsinghua.edu.cn/dart-pub" # pub: pub get
$ export PUB_HOSTED_URL="https://mirrors.tuna.tsinghua.edu.cn/dart-pub" # flutter: flutter packages get
~~~
若希望长期使用 TUNA 镜像:
~~~
$ echo 'export PUB_HOSTED_URL="https://mirrors.tuna.tsinghua.edu.cn/dart-pub"' >> ~/.bashrc
~~~
# 参考
[Using Flutter in China](https://github.com/flutter/flutter/wiki/Using-Flutter-in-China)