Flutter 环境搭建 (Win10)
从 Flutter 归档列表 下载 3.24.4
得到 flutter_windows_3.24.4-stable.zip
压缩包,解压至 %USERPROFILE%\dev
配置环境变量 %USERPROFILE%\dev\flutter\bin
执行命令 flutter doctor
查看是否存在问题
婴儿都能跟着学
转到目录,并创建 dev 文件夹
cd $env:USERPROFILE; mkdir dev; cd dev
下载 Flutter SDK 3.24.4
wget https://storage.flutter-io.cn/flutter_infra_release/releases/stable/windows/flutter_windows_3.24.4-stable.zip -OutFile flutter_windows_3.24.4-stable.zip
解压缩
Expand-Archive .\flutter_windows_3.24.4-stable.zip
添加 Flutter SDK 环境变量
$env:PATH = $pwd.PATH + "/flutter/bin",$env:PATH -join ";"
检查安装情况
flutter doctor
解决问题
无法将“flutter”项识别
flutter : 无法将“flutter”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
检查环境变量
echo $env:PATH
若是不存在 /flutter/bin
请手动添加
%USERPROFILE%\dev\flutter\bin
并再次检查。
信号灯超时时间已到
[!] Network resources
X A network error occurred while checking "https://maven.google.com/": 信号灯超时时间已到X A network error occurred while checking "https://github.com/": 信号灯超时时间已到
你的网络环境被强奸了,需要配置代理
假设 https proxy 地址是
localhost:7891
临时:
$Env:https_proxy="localhost:7891"
检查是否配置成功
echo $env:https_proxy
检查网络是否通畅
Test-NetConnection -ComputerName github.com
在此过程中使用 $env:
设置的环境变量仅适用于当前会话窗口。
✨ 配置系统环境变量使其永久生效
[System.Environment]::SetEnvironmentVariable("https_proxy", "http://localhost:7891", 'User')
若你需要移除可以使用
[System.Environment]::SetEnvironmentVariable("https_proxy", $null, 'User')
没有找到 Chrome
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
但是我们有 Edge
直接让 Flutter 与 Edge 结合,NTR Chrome
$Env:CHROME_EXECUTABLE="C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
在此过程中使用 $env:
设置的环境变量仅适用于当前会话窗口。
✨ 使其永久生效
[System.Environment]::SetEnvironmentVariable("CHROME_EXECUTABLE", "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", 'User')
Windows 版本检查时崩溃
[☠] Windows Version (the doctor check crashed)
X Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know
about this issue at https://github.com/flutter/flutter/issues.
X ProcessException: Failed to find "powershell" in the search path.
Command: powershell
你小子之前误删系统级环境变量 PATH 了?
检查目录是否存在
dir C:\Windows\System32\WindowsPowerShell\v1.0\
✨ 配置 PowerShell 至系统环境变量
[System.Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Windows\System32\WindowsPowerShell\v1.0\", 'Machine')
无法使用 package 功能
若您已经配置 https proxy 通常不会出现这个问题。
需要配置环境变量,以使用镜像站:
[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')