diff --git a/packages/flutter_tools/lib/src/windows/visual_studio.dart b/packages/flutter_tools/lib/src/windows/visual_studio.dart index 68c666b50b..7d67d4a010 100644 --- a/packages/flutter_tools/lib/src/windows/visual_studio.dart +++ b/packages/flutter_tools/lib/src/windows/visual_studio.dart @@ -47,7 +47,7 @@ class VisualStudio { /// The name of the Visual Studio install. /// /// For instance: "Visual Studio Community 2019". - String get displayName => _bestVisualStudioDetails[_displayNameKey] as String; + String? get displayName => _bestVisualStudioDetails[_displayNameKey] as String?; /// The user-friendly version number of the Visual Studio install. /// @@ -56,16 +56,16 @@ class VisualStudio { if (_bestVisualStudioDetails[_catalogKey] == null) { return null; } - return _bestVisualStudioDetails[_catalogKey][_catalogDisplayVersionKey] as String; + return _bestVisualStudioDetails[_catalogKey][_catalogDisplayVersionKey] as String?; } /// The directory where Visual Studio is installed. - String get installLocation => _bestVisualStudioDetails[_installationPathKey] as String; + String? get installLocation => _bestVisualStudioDetails[_installationPathKey] as String?; /// The full version of the Visual Studio install. /// /// For instance: "15.4.27004.2002". - String get fullVersion => _bestVisualStudioDetails[_fullVersionKey] as String; + String? get fullVersion => _bestVisualStudioDetails[_fullVersionKey] as String?; // Properties that determine the status of the installation. There might be // Visual Studio versions that don't include them, so default to a "valid" value to @@ -151,7 +151,7 @@ class VisualStudio { /// the components necessary to build. String? get cmakePath { final Map details = _usableVisualStudioDetails; - if (details.isEmpty) { + if (details.isEmpty || _usableVisualStudioDetails[_installationPathKey] == null) { return null; } return _fileSystem.path.joinAll([ @@ -168,7 +168,7 @@ class VisualStudio { } /// The major version of the Visual Studio install, as an integer. - int? get _majorVersion => fullVersion != null ? int.tryParse(fullVersion.split('.')[0]) : null; + int? get _majorVersion => fullVersion != null ? int.tryParse(fullVersion!.split('.')[0]) : null; /// The path to vswhere.exe. /// diff --git a/packages/flutter_tools/lib/src/windows/visual_studio_validator.dart b/packages/flutter_tools/lib/src/windows/visual_studio_validator.dart index ca6905e9cf..ebce8e619d 100644 --- a/packages/flutter_tools/lib/src/windows/visual_studio_validator.dart +++ b/packages/flutter_tools/lib/src/windows/visual_studio_validator.dart @@ -30,12 +30,12 @@ class VisualStudioValidator extends DoctorValidator { status = ValidationType.installed; messages.add(ValidationMessage( - _userMessages.visualStudioLocation(_visualStudio.installLocation) + _userMessages.visualStudioLocation(_visualStudio.installLocation ?? 'unknown') )); messages.add(ValidationMessage(_userMessages.visualStudioVersion( - _visualStudio.displayName, - _visualStudio.fullVersion, + _visualStudio.displayName ?? 'unknown', + _visualStudio.fullVersion ?? 'unknown', ))); if (_visualStudio.isPrerelease) { diff --git a/packages/flutter_tools/test/general.shard/base/os_test.dart b/packages/flutter_tools/test/general.shard/base/os_test.dart index 870c2ffe4a..dcc61f4af3 100644 --- a/packages/flutter_tools/test/general.shard/base/os_test.dart +++ b/packages/flutter_tools/test/general.shard/base/os_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:file/file.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/common.dart'; @@ -20,7 +18,7 @@ const String kPath1 = '/bar/bin/$kExecutable'; const String kPath2 = '/another/bin/$kExecutable'; void main() { - FakeProcessManager fakeProcessManager; + late FakeProcessManager fakeProcessManager; setUp(() { fakeProcessManager = FakeProcessManager.list([]); @@ -61,7 +59,7 @@ void main() { ), ); final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'linux')); - expect(utils.which(kExecutable).path, kPath1); + expect(utils.which(kExecutable)!.path, kPath1); }); testWithoutContext('returns all results for whichAll', () async { @@ -131,7 +129,7 @@ void main() { ), ); final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows')); - expect(utils.which(kExecutable).path, kPath1); + expect(utils.which(kExecutable)!.path, kPath1); }); testWithoutContext('returns all results for whichAll', () async { diff --git a/packages/flutter_tools/test/general.shard/linux/linux_doctor_test.dart b/packages/flutter_tools/test/general.shard/linux/linux_doctor_test.dart index ae06c92bca..543ef8c7ef 100644 --- a/packages/flutter_tools/test/general.shard/linux/linux_doctor_test.dart +++ b/packages/flutter_tools/test/general.shard/linux/linux_doctor_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_tools/src/base/user_messages.dart'; import 'package:flutter_tools/src/doctor_validator.dart'; import 'package:flutter_tools/src/linux/linux_doctor.dart'; diff --git a/packages/flutter_tools/test/general.shard/windows/visual_studio_test.dart b/packages/flutter_tools/test/general.shard/windows/visual_studio_test.dart index f60dc1c041..e3bc4cea7c 100644 --- a/packages/flutter_tools/test/general.shard/windows/visual_studio_test.dart +++ b/packages/flutter_tools/test/general.shard/windows/visual_studio_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart' show ProcessException; @@ -102,17 +100,17 @@ const List _requirementsBuildTools = [ void setMockVswhereResponse( FileSystem fileSystem, FakeProcessManager processManager, [ - List requiredComponents, - List additionalArguments, - Map response, - String responseOverride, - int exitCode, - Exception exception, + List? requiredComponents, + List? additionalArguments, + Map? response, + String? responseOverride, + int? exitCode, + Exception? exception, ]) { fileSystem.file(vswherePath).createSync(recursive: true); fileSystem.file(cmakePath).createSync(recursive: true); final String finalResponse = responseOverride - ?? json.encode(>[response]); + ?? (response != null ? json.encode(>[response]) : ''); final List requirementArguments = requiredComponents == null ? [] : ['-requires', ...requiredComponents]; @@ -127,7 +125,7 @@ void setMockVswhereResponse( '-utf8', '-latest', ...?additionalArguments, - ...?requirementArguments, + ...requirementArguments, ], stdout: finalResponse, exception: exception, @@ -138,11 +136,11 @@ void setMockVswhereResponse( // Sets whether or not a vswhere query with the required components will // return an installation. void setMockCompatibleVisualStudioInstallation( - Map response, + Map? response, FileSystem fileSystem, FakeProcessManager processManager, [ - int exitCode, - Exception exception, + int? exitCode, + Exception? exception, ]) { setMockVswhereResponse( fileSystem, @@ -159,11 +157,11 @@ void setMockCompatibleVisualStudioInstallation( // Sets whether or not a vswhere query with the required components will // return a pre-release installation. void setMockPrereleaseVisualStudioInstallation( - Map response, + Map? response, FileSystem fileSystem, FakeProcessManager processManager, [ - int exitCode, - Exception exception, + int? exitCode, + Exception? exception, ]) { setMockVswhereResponse( fileSystem, @@ -180,11 +178,11 @@ void setMockPrereleaseVisualStudioInstallation( // Sets whether or not a vswhere query with the required components will // return an Build Tools installation. void setMockCompatibleVisualStudioBuildToolsInstallation( - Map response, + Map? response, FileSystem fileSystem, FakeProcessManager processManager, [ - int exitCode, - Exception exception, + int? exitCode, + Exception? exception, ]) { setMockVswhereResponse( fileSystem, @@ -201,11 +199,11 @@ void setMockCompatibleVisualStudioBuildToolsInstallation( // Sets whether or not a vswhere query with the required components will // return a pre-release Build Tools installation. void setMockPrereleaseVisualStudioBuildToolsInstallation( - Map response, + Map? response, FileSystem fileSystem, FakeProcessManager processManager, [ - int exitCode, - Exception exception, + int? exitCode, + Exception? exception, ]) { setMockVswhereResponse( fileSystem, @@ -222,11 +220,11 @@ void setMockPrereleaseVisualStudioBuildToolsInstallation( // Sets whether or not a vswhere query searching for 'all' and 'prerelease' // versions will return an installation. void setMockAnyVisualStudioInstallation( - Map response, + Map? response, FileSystem fileSystem, FakeProcessManager processManager, [ - int exitCode, - Exception exception, + int? exitCode, + Exception? exception, ]) { setMockVswhereResponse( fileSystem,