一、问题描述
在配置flutter环境的过程中,出现了以下问题:
Windows Version (Unable to confirm if installed Windows version is 10 or greater)
二、解决问题
我已经能够重现该问题。事实上,正如@liscanso首先发现的那样,它与系统语言有关,因为没有参数的命令输出是依赖于语言的。所以我提出了一个可以帮助绕过这个问题的修复程序。systeminfo
1、把该目录下的文件替换为下面的代码(它与原点相同,但进行了一些调整):(FLUTTER-SDK-DIR)\packages\flutter_tools\lib\src\windows\windows_version_validator.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,
);
}
}
2、删除文件。(FLUTTER-SDK-DIR)\bin\cache\flutter_tools.stamp/
3、再跑一次。flutter doctor
OK,问题解决!
三、解决问题的原理
基本上,我改变了 Flutter 检查 Windows 版本的方式,通过分析快速、更高效的输出,而不是检查长期命令中依赖于语言的输出。这是在空格字符处拆分输出,获取第四个值(位置 3),在点处再次拆分,将第一个值(位置 0)转换为 int 并检查它是否大于或等于 10 的问题。无需正则表达式。versysteminfo
也许这里的一些贡献者可以测试我的解决方案并合并代码,因此不再需要手动解决方法。文章来源:https://www.toymoban.com/news/detail-505379.html
四、引用原文
issues - Cantasura的评论。文章来源地址https://www.toymoban.com/news/detail-505379.html
到了这里,关于在配置Flutter环境遇到:× Windows Version (Unable to confirm if installed Windows version is 10 or greater)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!