Loading... <div class="tip share">请注意,本文编写于 799 天前,最后修改于 194 天前,其中某些信息可能已经过时。</div> # 前言 在不久前,flutter官方于 `2023.01.25`在stable渠道发布了3.7.0版本(不得不说从3.3到3.7跨度挺大)我原本的环境是 `flutter-3.3.8`版本。在stabel渠道发布到3.7.3版本之后,我也下载了这个版本的sdk来尝试使用。 当然,我是创建了另外的目录来保存3.7.3版本的sdk,方便在翻车后进行版本回退。就在我运行 `flutter doctor`后,他给我报错了 `[X] Windows Version (Unable to confirm if installed Windows version is 10 or greater)`  不过当时在我切换渠道为master渠道后,又恢复正常了,于是就放着不管了(因为当时我感觉用不上3.7.3版本,就先回退3.3.8版本了,目前做的几个project也够用) ## 出大问题 没多久,我打算用flutter写一个桌面端程序,但是在windows中使用 `Material`风格属实很怪异,所以我打算使用 `fluent_ui`插件来编写,可问题来了,我使用3.3.8版本会提示版本不兼容,没办法,只好用3.7版本了,可是就在我写了没多少代码的时候运行,又又报错了,是fluent_ui给出的报错,查询了一番这个报错貌似是需要我使用3.7版本?欸不对啊,我已经换了3.7版本了呀。 结果我再运行一看,master渠道已经到3.8版本了,没办法,只能降级了。此时stable的版本已经是3.7.4了,切换渠道也不管用,所以只能找方法去解决了。 去官方的issues里发现很多人的情况和我一样,是系统语言导致的,英文版本貌似就没有问题。 **解决方法链接在这 [解决方法](https://github.com/flutter/flutter/issues/117890#issuecomment-1405975179)** # 解决方法 找到你存放的flutter sdk路径,找到这个文件 `/packages/flutter_tools/lib/src/windows/windows_version_validator.dart` 将原先的代码改为如下所示(建议进行备份,随着版本迭代可能在以后的版本会失效) ```dart // Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:process/process.dart'; import '../base/io.dart'; import '../doctor_validator.dart'; // FIX #1 - Remove everything from line 10 to 20 in original source code. /// Validator for supported Windows host machine operating system version. class WindowsVersionValidator extends DoctorValidator { const WindowsVersionValidator({required ProcessManager processManager}) : _processManager = processManager, super('Windows Version'); final ProcessManager _processManager; @override Future<ValidationResult> validate() async { // FIX #2 - Replace 'systeminfo' by 'ver' command final ProcessResult result = await _processManager.run(<String>['ver'], runInShell: true); if (result.exitCode != 0) { return const ValidationResult( ValidationType.missing, <ValidationMessage>[], statusInfo: 'Exit status from running `systeminfo` was unsuccessful', ); } final String resultStdout = result.stdout as String; // FIX #3 - Remove brackets from output final String resultAdjusted = resultStdout.replaceAll('[','').replaceAll(']',''); // FIX #4 - Split the output at spaces, and get Windows version at position 3. // Split again at dots and get the major version at position 0. // Cast the output to int. final int winver = int.parse(resultAdjusted.split(' ').elementAt(3).split('.').elementAt(0)); // Use the string split method to extract the major version // and check against the [kUnsupportedVersions] list final ValidationType windowsVersionStatus; final String statusInfo; // FIX #5 - Check if Windows major version is greater than 10. // Succeeds if true. if (winver >= 10) { windowsVersionStatus = ValidationType.installed; statusInfo = 'Installed version of Windows is version 10 or higher'; } else { windowsVersionStatus = ValidationType.missing; statusInfo = 'Unable to confirm if installed Windows version is 10 or greater'; } return ValidationResult( windowsVersionStatus, const <ValidationMessage>[], statusInfo: statusInfo, ); } } ``` 然后我们再删除flutter sdk目录下的 `flutter-sdk-dir\bin\cache\flutter_tools.stampw`文件 最后我们运行下 `flutter doctor`,问题解决  感兴趣的可以看一下源代码,对比原来代码和更改后的代码的不同之处,方便后继出问题了也可以解决 根据解决方案提出者的原话 `Basically I changed the way Flutter checks Windows version, by analyzing a fast and more efficient `ver `output instead of checking a language-dependent output from a longstanding`systeminfo ` command. It's a matter of splitting the output at space characters, getting the fourth value (position 3), splitting again at dots, casting the first value (position 0) to int and checking if it's greater than or equal to 10. No regex needed.` 我们可以知道是检查windows的方式有问题。 <div class="tip inlineBlock warning"> 在master中貌似已经修复了doctor验证程序 </div> Last modification:October 19, 2024 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 3 如果觉得我的文章对你有用,请随意赞赏