- 首先设置 Flutter 的镜像环境变量(在 PowerShell 中运行):
# 设置 Flutter 镜像
$env:PUB_HOSTED_URL="https://pub.flutter-io.cn"
$env:FLUTTER_STORAGE_BASE_URL="https://storage.flutter-io.cn"
# 将这些环境变量永久保存
[System.Environment]::SetEnvironmentVariable('PUB_HOSTED_URL', 'https://pub.flutter-io.cn', 'User')
[System.Environment]::SetEnvironmentVariable('FLUTTER_STORAGE_BASE_URL', 'https://storage.flutter-io.cn', 'User')
转自
2. 使用 Git 克隆 Flutter SDK(选择一个目录,比如 D:\development):
# 创建目录
mkdir D:\development
cd D:\development
# 克隆 Flutter 仓库
git clone https://github.com/flutter/flutter.git -b stable
- 添加 Flutter 到环境变量:
# 添加 Flutter bin 目录到用户环境变量
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
$flutterPath = "D:\development\flutter\bin"
[Environment]::SetEnvironmentVariable('Path', "$userPath;$flutterPath", 'User')
- 重新打开新的 PowerShell 窗口,运行 Flutter doctor 检查环境:
flutter doctor
如果 GitHub 访问较慢,可以使用 Gitee 镜像:
git clone https://gitee.com/mirrors/Flutter.git -b stable flutter
注意事项:
- 确保已经安装了 Git
- 安装路径不要包含中文和特殊字符
- 如果
flutter doctor
提示需要安装其他组件:- Android Studio
- Visual Studio(安装 Desktop development with C++)
- VS Code
常见问题解决:
- 如果下载速度慢,可以使用 Git 代理:
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
- 如果需要取消代理:
git config --global --unset http.proxy
git config --global --unset https.proxy
完成安装后,可以验证安装:
flutter --version
flutter doctor