中国特色

如果您在中国安装或使用Flutter,你可能需要使用本地镜像网站来提高依赖下载速度。 要让Flutter工具使用存镜像站点,您需要在运行Flutter命令之前设置两个环境变量,PUB_HOSTED_URLFLUTTER_STORAGE_BASE_URL

下面使用MacOS或Linux作为示例,以下是使用镜像站点的设置过程中的前几个步骤。 在你的Bash shell环境中运行以下命令:

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

上海交通大学镜像

export FLUTTER_STORAGE_BASE_URL=https://mirrors.sjtug.sjtu.edu.cn/
export PUB_HOSTED_URL=https://dart-pub.mirrors.sjtug.sjtu.edu.cn/

将FLUTTER_STORAGE_BASE_URL和PUB_HOSTED_URL环境变量持久化

zsh

echo FLUTTER_STORAGE_BASE_URL=https://mirrors.sjtug.sjtu.edu.cn/ >> ~/.zshrc

echo PUB_HOSTED_URL=https://dart-pub.mirrors.sjtug.sjtu.edu.cn/ >> ~/.zshrc

bash

echo  FLUTTER_STORAGE_BASE_URL=https://mirrors.sjtug.sjtu.edu.cn/ >> ~/.bashrc

echo PUB_HOSTED_URL=https://dart-pub.mirrors.sjtug.sjtu.edu.cn/ >> ~/.bashrc