diff --git a/packages/flutter_tools/lib/src/base/common.dart b/packages/flutter_tools/lib/src/base/common.dart index b0115473f6..be5c4723ec 100644 --- a/packages/flutter_tools/lib/src/base/common.dart +++ b/packages/flutter_tools/lib/src/base/common.dart @@ -6,7 +6,7 @@ /// where the tool should exit with a clear message to the user /// and no stack trace unless the --verbose option is specified. /// For example: network errors. -Never throwToolExit(String message, { int? exitCode }) { +Never throwToolExit(String? message, { int? exitCode }) { throw ToolExit(message, exitCode: exitCode); } diff --git a/packages/flutter_tools/lib/src/commands/channel.dart b/packages/flutter_tools/lib/src/commands/channel.dart index 332509bdfb..c100112c3c 100644 --- a/packages/flutter_tools/lib/src/commands/channel.dart +++ b/packages/flutter_tools/lib/src/commands/channel.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 '../base/common.dart'; import '../cache.dart'; import '../globals.dart' as globals; @@ -16,7 +14,6 @@ class ChannelCommand extends FlutterCommand { 'all', abbr: 'a', help: 'Include all the available branches (including local branches) when listing channels.', - defaultsTo: false, hide: !verboseHelp, ); } @@ -31,29 +28,30 @@ class ChannelCommand extends FlutterCommand { final String category = FlutterCommandCategory.sdk; @override - String get invocation => '${runner.executableName} $name []'; + String get invocation => '${runner?.executableName} $name []'; @override Future> get requiredArtifacts async => const {}; @override Future runCommand() async { - switch (argResults.rest.length) { + final List rest = argResults?.rest ?? []; + switch (rest.length) { case 0: await _listChannels( showAll: boolArg('all'), - verbose: globalResults['verbose'] as bool, + verbose: globalResults?['verbose'] == true, ); return FlutterCommandResult.success(); case 1: - await _switchChannel(argResults.rest[0]); + await _switchChannel(rest[0]); return FlutterCommandResult.success(); default: throw ToolExit('Too many arguments.\n$usage'); } } - Future _listChannels({ bool showAll, bool verbose }) async { + Future _listChannels({ required bool showAll, required bool verbose }) async { // Beware: currentBranch could contain PII. See getBranchName(). final String currentChannel = globals.flutterVersion.channel; final String currentBranch = globals.flutterVersion.getBranchName(); diff --git a/packages/flutter_tools/lib/src/commands/clean.dart b/packages/flutter_tools/lib/src/commands/clean.dart index ee80dd268e..e72abddbcb 100644 --- a/packages/flutter_tools/lib/src/commands/clean.dart +++ b/packages/flutter_tools/lib/src/commands/clean.dart @@ -2,10 +2,9 @@ // 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:meta/meta.dart'; +import '../../src/macos/xcode.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; import '../build_info.dart'; @@ -40,7 +39,8 @@ class CleanCommand extends FlutterCommand { // Clean Xcode to remove intermediate DerivedData artifacts. // Do this before removing ephemeral directory, which would delete the xcworkspace. final FlutterProject flutterProject = FlutterProject.current(); - if (globals.xcode.isInstalledAndMeetsVersionCheck) { + final Xcode? xcode = globals.xcode; + if (xcode != null && xcode.isInstalledAndMeetsVersionCheck) { await _cleanXcode(flutterProject.ios); await _cleanXcode(flutterProject.macos); } @@ -78,15 +78,16 @@ class CleanCommand extends FlutterCommand { 'Cleaning Xcode workspace...', ); try { + final XcodeProjectInterpreter xcodeProjectInterpreter = globals.xcodeProjectInterpreter!; final Directory xcodeWorkspace = xcodeProject.xcodeWorkspace; - final XcodeProjectInfo projectInfo = await globals.xcodeProjectInterpreter.getInfo(xcodeWorkspace.parent.path); + final XcodeProjectInfo projectInfo = await xcodeProjectInterpreter.getInfo(xcodeWorkspace.parent.path); for (final String scheme in projectInfo.schemes) { - await globals.xcodeProjectInterpreter.cleanWorkspace(xcodeWorkspace.path, scheme, verbose: _verbose); + await xcodeProjectInterpreter.cleanWorkspace(xcodeWorkspace.path, scheme, verbose: _verbose); } } on Exception catch (error) { globals.printTrace('Could not clean Xcode workspace: $error'); } finally { - xcodeStatus?.stop(); + xcodeStatus.stop(); } } diff --git a/packages/flutter_tools/lib/src/commands/config.dart b/packages/flutter_tools/lib/src/commands/config.dart index e34db37a6b..d7913e8a5c 100644 --- a/packages/flutter_tools/lib/src/commands/config.dart +++ b/packages/flutter_tools/lib/src/commands/config.dart @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - +import '../../src/android/android_sdk.dart'; +import '../../src/android/android_studio.dart'; import '../base/common.dart'; import '../convert.dart'; import '../features.dart'; @@ -14,7 +14,6 @@ import '../runner/flutter_command.dart'; class ConfigCommand extends FlutterCommand { ConfigCommand({ bool verboseHelp = false }) { argParser.addFlag('analytics', - negatable: true, help: 'Enable or disable reporting anonymously tool usage statistics and crash reports.'); argParser.addFlag('clear-ios-signing-cert', negatable: false, @@ -28,13 +27,13 @@ class ConfigCommand extends FlutterCommand { hide: !verboseHelp, help: 'Print config values as json.'); for (final Feature feature in allFeatures) { - if (feature.configSetting == null) { + final String? configSetting = feature.configSetting; + if (configSetting == null) { continue; } argParser.addFlag( - feature.configSetting, + configSetting, help: feature.generateHelpMessage(), - negatable: true, ); } argParser.addFlag( @@ -70,15 +69,16 @@ class ConfigCommand extends FlutterCommand { final Map featuresByName = {}; final String channel = globals.flutterVersion.channel; for (final Feature feature in allFeatures) { - if (feature.configSetting != null) { - featuresByName[feature.configSetting] = feature; + final String? configSetting = feature.configSetting; + if (configSetting != null) { + featuresByName[configSetting] = feature; } } String values = globals.config.keys .map((String key) { String configFooter = ''; if (featuresByName.containsKey(key)) { - final FeatureChannelSetting setting = featuresByName[key].getSettingForChannel(channel); + final FeatureChannelSetting setting = featuresByName[key]!.getSettingForChannel(channel); if (!setting.available) { configFooter = '(Unavailable)'; } @@ -97,7 +97,7 @@ class ConfigCommand extends FlutterCommand { /// Return null to disable analytics recording of the `config` command. @override - Future get usagePath async => null; + Future get usagePath async => null; @override Future runCommand() async { @@ -108,14 +108,15 @@ class ConfigCommand extends FlutterCommand { if (boolArg('clear-features')) { for (final Feature feature in allFeatures) { - if (feature.configSetting != null) { - globals.config.removeValue(feature.configSetting); + final String? configSetting = feature.configSetting; + if (configSetting != null) { + globals.config.removeValue(configSetting); } } return FlutterCommandResult.success(); } - if (argResults.wasParsed('analytics')) { + if (argResults?.wasParsed('analytics') == true) { final bool value = boolArg('analytics'); // The tool sends the analytics event *before* toggling the flag // intentionally to be sure that opt-out events are sent correctly. @@ -130,20 +131,20 @@ class ConfigCommand extends FlutterCommand { globals.printStatus('Analytics reporting ${value ? 'enabled' : 'disabled'}.'); } - if (argResults.wasParsed('android-sdk')) { - _updateConfig('android-sdk', stringArg('android-sdk')); + if (argResults?.wasParsed('android-sdk') == true) { + _updateConfig('android-sdk', stringArg('android-sdk')!); } - if (argResults.wasParsed('android-studio-dir')) { - _updateConfig('android-studio-dir', stringArg('android-studio-dir')); + if (argResults?.wasParsed('android-studio-dir') == true) { + _updateConfig('android-studio-dir', stringArg('android-studio-dir')!); } - if (argResults.wasParsed('clear-ios-signing-cert')) { + if (argResults?.wasParsed('clear-ios-signing-cert') == true) { _updateConfig('ios-signing-cert', ''); } - if (argResults.wasParsed('build-dir')) { - final String buildDir = stringArg('build-dir'); + if (argResults?.wasParsed('build-dir') == true) { + final String buildDir = stringArg('build-dir')!; if (globals.fs.path.isAbsolute(buildDir)) { throwToolExit('build-dir should be a relative path'); } @@ -151,17 +152,18 @@ class ConfigCommand extends FlutterCommand { } for (final Feature feature in allFeatures) { - if (feature.configSetting == null) { + final String? configSetting = feature.configSetting; + if (configSetting == null) { continue; } - if (argResults.wasParsed(feature.configSetting)) { - final bool keyValue = boolArg(feature.configSetting); - globals.config.setValue(feature.configSetting, keyValue); - globals.printStatus('Setting "${feature.configSetting}" value to "$keyValue".'); + if (argResults?.wasParsed(configSetting) == true) { + final bool keyValue = boolArg(configSetting); + globals.config.setValue(configSetting, keyValue); + globals.printStatus('Setting "$configSetting" value to "$keyValue".'); } } - if (argResults.arguments.isEmpty) { + if (argResults == null || argResults!.arguments.isEmpty) { globals.printStatus(usage); } else { globals.printStatus('\nYou may need to restart any open editors for them to read new settings.'); @@ -172,17 +174,19 @@ class ConfigCommand extends FlutterCommand { Future handleMachine() async { // Get all the current values. - final Map results = {}; + final Map results = {}; for (final String key in globals.config.keys) { results[key] = globals.config.getValue(key); } // Ensure we send any calculated ones, if overrides don't exist. - if (results['android-studio-dir'] == null && globals.androidStudio != null) { - results['android-studio-dir'] = globals.androidStudio.directory; + final AndroidStudio? androidStudio = globals.androidStudio; + if (results['android-studio-dir'] == null && androidStudio != null) { + results['android-studio-dir'] = androidStudio.directory; } - if (results['android-sdk'] == null && globals.androidSdk != null) { - results['android-sdk'] = globals.androidSdk.directory.path; + final AndroidSdk? androidSdk = globals.androidSdk; + if (results['android-sdk'] == null && androidSdk != null) { + results['android-sdk'] = androidSdk.directory.path; } globals.printStatus(const JsonEncoder.withIndent(' ').convert(results)); diff --git a/packages/flutter_tools/lib/src/commands/debug_adapter.dart b/packages/flutter_tools/lib/src/commands/debug_adapter.dart index 5ec797b67a..641b168a9d 100644 --- a/packages/flutter_tools/lib/src/commands/debug_adapter.dart +++ b/packages/flutter_tools/lib/src/commands/debug_adapter.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 'dart:async'; import '../debug_adapters/server.dart'; @@ -31,7 +29,6 @@ class DebugAdapterCommand extends FlutterCommand { argParser .addFlag( 'test', - defaultsTo: false, help: 'Whether to use the "flutter test" debug adapter to run tests' ' and emit custom events for test progress/results.', ); @@ -59,9 +56,9 @@ class DebugAdapterCommand extends FlutterCommand { globals.stdio.stdout.nonBlocking, fileSystem: globals.fs, platform: globals.platform, - ipv6: ipv6, + ipv6: ipv6 == true, enableDds: enableDds, - test: boolArg('test') ?? false, + test: boolArg('test'), ); await server.channel.closed; diff --git a/packages/flutter_tools/lib/src/commands/devices.dart b/packages/flutter_tools/lib/src/commands/devices.dart index 2596150157..2c197271f1 100644 --- a/packages/flutter_tools/lib/src/commands/devices.dart +++ b/packages/flutter_tools/lib/src/commands/devices.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 '../base/common.dart'; import '../base/utils.dart'; import '../convert.dart'; @@ -20,7 +18,6 @@ class DevicesCommand extends FlutterCommand { argParser.addOption( 'timeout', abbr: 't', - defaultsTo: null, help: '(deprecated) This option has been replaced by "--${FlutterOptions.kDeviceTimeout}".', hide: !verboseHelp, ); @@ -37,9 +34,9 @@ class DevicesCommand extends FlutterCommand { final String category = FlutterCommandCategory.tools; @override - Duration get deviceDiscoveryTimeout { - if (argResults['timeout'] != null) { - final int timeoutSeconds = int.tryParse(stringArg('timeout')); + Duration? get deviceDiscoveryTimeout { + if (argResults?['timeout'] != null) { + final int? timeoutSeconds = int.tryParse(stringArg('timeout')!); if (timeoutSeconds == null) { throwToolExit('Could not parse -t/--timeout argument. It must be an integer.'); } @@ -50,7 +47,7 @@ class DevicesCommand extends FlutterCommand { @override Future validateCommand() { - if (argResults['timeout'] != null) { + if (argResults?['timeout'] != null) { globals.printError('${globals.logger.terminal.warningMark} The "--timeout" argument is deprecated; use "--${FlutterOptions.kDeviceTimeout}" instead.'); } return super.validateCommand(); @@ -58,14 +55,14 @@ class DevicesCommand extends FlutterCommand { @override Future runCommand() async { - if (!globals.doctor.canListAnything) { + if (globals.doctor?.canListAnything != true) { throwToolExit( "Unable to locate a development device; please run 'flutter doctor' for " 'information about installing additional components.', exitCode: 1); } - final List devices = await globals.deviceManager.refreshAllConnectedDevices(timeout: deviceDiscoveryTimeout); + final List devices = await globals.deviceManager?.refreshAllConnectedDevices(timeout: deviceDiscoveryTimeout) ?? []; if (boolArg('machine')) { await printDevicesAsJson(devices); @@ -93,7 +90,7 @@ class DevicesCommand extends FlutterCommand { } Future _printDiagnostics() async { - final List diagnostics = await globals.deviceManager.getDeviceDiagnostics(); + final List diagnostics = await globals.deviceManager?.getDeviceDiagnostics() ?? []; if (diagnostics.isNotEmpty) { globals.printStatus(''); for (final String diagnostic in diagnostics) { diff --git a/packages/flutter_tools/lib/src/commands/logs.dart b/packages/flutter_tools/lib/src/commands/logs.dart index 486c1cd4cf..f5f1f37243 100644 --- a/packages/flutter_tools/lib/src/commands/logs.dart +++ b/packages/flutter_tools/lib/src/commands/logs.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 'dart:async'; import '../base/common.dart'; @@ -34,10 +32,10 @@ class LogsCommand extends FlutterCommand { @override Future> get requiredArtifacts async => const {}; - Device device; + Device? device; @override - Future verifyThenRunCommand(String commandPath) async { + Future verifyThenRunCommand(String? commandPath) async { device = await findTargetDevice(includeUnsupportedDevices: true); if (device == null) { throwToolExit(null); @@ -47,11 +45,12 @@ class LogsCommand extends FlutterCommand { @override Future runCommand() async { + final Device cachedDevice = device!; if (boolArg('clear')) { - device.clearLogs(); + cachedDevice.clearLogs(); } - final DeviceLogReader logReader = await device.getLogReader(); + final DeviceLogReader logReader = await cachedDevice.getLogReader(); globals.printStatus('Showing $logReader logs:'); diff --git a/packages/flutter_tools/lib/src/commands/make_host_app_editable.dart b/packages/flutter_tools/lib/src/commands/make_host_app_editable.dart index 3fcb8669f1..907ce6090b 100644 --- a/packages/flutter_tools/lib/src/commands/make_host_app_editable.dart +++ b/packages/flutter_tools/lib/src/commands/make_host_app_editable.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 '../runner/flutter_command.dart'; class MakeHostAppEditableCommand extends FlutterCommand {