You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter安装异常求助:版本识别错误致命令无法执行

问题描述

我按官方文档安装Flutter并将bin目录加入环境变量,但全局执行flutter doctor时出现版本识别错误,显示版本为0.0.0-unknown,且提示上游仓库源异常;但直接在Flutter的bin目录内执行flutter doctor却能正常识别版本(3.16.5)。这导致VS Code中执行flutter pub get和flutter --version失败,依赖版本校验不通过。

全局执行异常输出:

C:\Users\Mohammed\Desktop\flutter\flutter>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel stable, 0.0.0-unknown, on Microsoft Windows [Version 10.0.22621.2861], locale en-US)
    ! Flutter version 0.0.0-unknown on channel stable at
      C:\Users\Mohammed\Downloads\flutter_windows_3.13.9-stable\flutter
      Cannot resolve current version, possibly due to local changes.
      Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.2.5)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop
      development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.85.1)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 2 categories.

bin目录内正常输出:

C:\Users\Mohammed\Desktop\flutter\flutter\bin>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.16.5, on Microsoft Windows [Version 10.0.22621.2861], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.2.5)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop
      development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.85.1)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 1 category.

VS Code中执行错误:

PS C:\Users\Mohammed\Downloads\Telegram Desktop\myflutter_assignment> flutter pub get
Resolving dependencies... (1.0s)
The current Flutter SDK version is 0.0.0-unknown.

Because myflutter_assignment depends on go_router >=0.2.0 which requires Flutter SDK version >=1.17.0, version solving failed.


You can try the following suggestion to make the pubspec resolve:
* Try using the Flutter SDK version: 3.16.5.



PS C:\Users\Mohammed\Downloads\Telegram Desktop\myflutter_assignment> flutter --version
Flutter • channel stable • unknown source
Framework • revision  () • 1970-01-01 03:00:00.000
Engine • revision 0545f8705d
Tools • Dart 3.1.5 • DevTools 2.25.0
解决方案

1. 修正环境变量配置

  • 打开系统环境变量设置,找到Path变量,确认添加的Flutter bin目录路径为正确的版本目录:
    • 正确路径应为C:\Users\Mohammed\Desktop\flutter\flutter\bin(对应你bin目录内执行正常的路径)
    • 删除旧的错误路径(如C:\Users\Mohammed\Downloads\flutter_windows_3.13.9-stable\flutter\bin),保存后重启所有终端和VS Code

2. 重置Flutter仓库源

如果环境变量配置正确仍有问题,执行以下步骤:

  • 打开终端,进入正确的Flutter安装根目录(C:\Users\Mohammed\Desktop\flutter\flutter)
  • 执行Git命令重置仓库远程源:
    git remote set-url origin https://github.com/flutter/flutter.git
    
  • 执行flutter upgrade拉取最新仓库信息,重新识别版本

3. 指定VS Code的Flutter SDK路径

打开VS Code,按Ctrl+Shift+P调出命令面板,输入Flutter: Change SDK Path,选择正确的Flutter安装根目录(C:\Users\Mohammed\Desktop\flutter\flutter),保存后重启VS Code

4. 验证修复效果

  • 打开新终端,全局执行flutter doctor和flutter --version,确认版本显示为3.16.5
  • 在项目目录执行flutter pub get,确认依赖可正常解析

内容的提问来源于stack exchange,提问作者Mame

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 20:43:23