From 92034482f9a6a0e9623380768f53cb5125e216f1 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 15 Jun 2022 13:02:07 -0700 Subject: [PATCH] [flutter_tool] partial null safety migration of tool source code (#105798) --- dev/bots/test.dart | 1 + packages/flutter_tools/lib/executable.dart | 28 +- packages/flutter_tools/lib/runner.dart | 34 +- .../lib/src/android/android_workflow.dart | 22 +- .../lib/src/android/application_package.dart | 4 +- .../flutter_tools/lib/src/base/utils.dart | 4 +- .../lib/src/commands/attach.dart | 107 ++-- .../lib/src/commands/custom_devices.dart | 198 +++--- .../lib/src/commands/daemon.dart | 400 ++++++------ .../flutter_tools/lib/src/commands/drive.dart | 74 +-- .../lib/src/commands/precache.dart | 64 +- .../flutter_tools/lib/src/commands/run.dart | 111 ++-- .../flutter_tools/lib/src/commands/test.dart | 35 +- .../flutter_tools/lib/src/context_runner.dart | 54 +- packages/flutter_tools/lib/src/daemon.dart | 2 +- .../flutter_tools/lib/src/desktop_device.dart | 2 +- packages/flutter_tools/lib/src/devfs.dart | 4 +- packages/flutter_tools/lib/src/device.dart | 8 +- .../lib/src/devtools_launcher.dart | 36 +- .../lib/src/drive/drive_service.dart | 108 ++-- .../lib/src/drive/web_driver_service.dart | 82 ++- .../lib/src/flutter_application_package.dart | 6 +- .../lib/src/flutter_device_manager.dart | 2 +- .../flutter_tools/lib/src/ios/simulators.dart | 2 +- .../lib/src/isolated/devfs_web.dart | 283 ++++----- .../lib/src/isolated/resident_web_runner.dart | 278 +++++---- .../src/isolated/sdk_web_configuration.dart | 9 +- .../flutter_tools/lib/src/preview_device.dart | 2 +- .../lib/src/resident_devtools_handler.dart | 106 ++-- .../lib/src/resident_runner.dart | 576 +++++++++--------- packages/flutter_tools/lib/src/run_cold.dart | 87 ++- packages/flutter_tools/lib/src/run_hot.dart | 517 ++++++++-------- .../lib/src/runner/flutter_command.dart | 6 +- .../lib/src/test/coverage_collector.dart | 88 +-- .../lib/src/test/flutter_platform.dart | 118 ++-- .../lib/src/test/flutter_tester_device.dart | 97 +-- .../lib/src/test/flutter_web_goldens.dart | 55 +- .../lib/src/test/flutter_web_platform.dart | 151 +++-- .../lib/src/test/integration_test_device.dart | 4 +- .../flutter_tools/lib/src/test/runner.dart | 82 ++- .../lib/src/test/test_compiler.dart | 43 +- packages/flutter_tools/lib/src/vmservice.dart | 11 +- .../flutter_tools/lib/src/web/web_runner.dart | 26 +- .../flutter_tester_device_test.dart | 8 - .../resident_web_runner_cold_test.dart | 5 - .../resident_web_runner_test.dart | 11 +- .../general.shard/web/devfs_web_test.dart | 2 + .../test/src/fake_vm_services.dart | 4 +- 48 files changed, 1932 insertions(+), 2025 deletions(-) diff --git a/dev/bots/test.dart b/dev/bots/test.dart index 087f4ed932ee..47b7d5331629 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -339,6 +339,7 @@ Future _runGeneralToolTests() async { _toolsPath, testPaths: [path.join('test', 'general.shard')], enableFlutterToolAsserts: false, + // Detect unit test time regressions (poor time delay handling, etc). // This overrides the 15 minute default for tools tests. // See the README.md and dart_test.yaml files in the flutter_tools package. diff --git a/packages/flutter_tools/lib/executable.dart b/packages/flutter_tools/lib/executable.dart index 01223506e408..205ca86f7eb2 100644 --- a/packages/flutter_tools/lib/executable.dart +++ b/packages/flutter_tools/lib/executable.dart @@ -2,10 +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:meta/meta.dart'; - import 'runner.dart' as runner; import 'src/artifacts.dart'; import 'src/base/context.dart'; @@ -110,7 +106,7 @@ Future main(List args) async { // devtools source code. DevtoolsLauncher: () => DevtoolsServerLauncher( processManager: globals.processManager, - dartExecutable: globals.artifacts.getHostArtifact(HostArtifact.engineDartBinary).path, + dartExecutable: globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path, logger: globals.logger, botDetector: globals.botDetector, ), @@ -134,8 +130,8 @@ Future main(List args) async { } List generateCommands({ - @required bool verboseHelp, - @required bool verbose, + required bool verboseHelp, + required bool verbose, }) => [ AnalyzeCommand( verboseHelp: verboseHelp, @@ -144,7 +140,7 @@ List generateCommands({ processManager: globals.processManager, logger: globals.logger, terminal: globals.terminal, - artifacts: globals.artifacts, + artifacts: globals.artifacts!, ), AssembleCommand(verboseHelp: verboseHelp, buildSystem: globals.buildSystem), AttachCommand(verboseHelp: verboseHelp), @@ -210,9 +206,9 @@ List generateCommands({ /// Our logger class hierarchy and runtime requirements are overly complicated. class LoggerFactory { LoggerFactory({ - @required Terminal terminal, - @required Stdio stdio, - @required OutputPreferences outputPreferences, + required Terminal terminal, + required Stdio stdio, + required OutputPreferences outputPreferences, StopwatchFactory stopwatchFactory = const StopwatchFactory(), }) : _terminal = terminal, _stdio = stdio, @@ -226,11 +222,11 @@ class LoggerFactory { /// Create the appropriate logger for the current platform and configuration. Logger createLogger({ - @required bool verbose, - @required bool prefixedErrors, - @required bool machine, - @required bool daemon, - @required bool windows, + required bool verbose, + required bool prefixedErrors, + required bool machine, + required bool daemon, + required bool windows, }) { Logger logger; if (windows) { diff --git a/packages/flutter_tools/lib/runner.dart b/packages/flutter_tools/lib/runner.dart index c32ff13b5b1e..5c824b6e05ac 100644 --- a/packages/flutter_tools/lib/runner.dart +++ b/packages/flutter_tools/lib/runner.dart @@ -2,7 +2,7 @@ // 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'; @@ -31,9 +31,9 @@ Future run( bool muteCommandLogging = false, bool verbose = false, bool verboseHelp = false, - bool reportCrashes, - String flutterVersion, - Map overrides, + bool? reportCrashes, + String? flutterVersion, + Map? overrides, }) async { if (muteCommandLogging) { // Remove the verbose option; for help and doctor, users don't need to see @@ -55,8 +55,8 @@ Future run( ); String getVersion() => flutterVersion ?? globals.flutterVersion.getVersionString(redactUnknownBranches: true); - Object firstError; - StackTrace firstStackTrace; + Object? firstError; + StackTrace? firstStackTrace; return runZoned>(() async { try { await runner.run(args); @@ -74,7 +74,7 @@ Future run( // This catches all exceptions to send to crash logging, etc. firstError = error; firstStackTrace = stackTrace; - return _handleToolError(error, stackTrace, verbose, args, reportCrashes, getVersion); + return _handleToolError(error, stackTrace, verbose, args, reportCrashes!, getVersion); } }, onError: (Object error, StackTrace stackTrace) async { // ignore: deprecated_member_use // If sending a crash report throws an error into the zone, we don't want @@ -82,14 +82,14 @@ Future run( // to send the original error that triggered the crash report. firstError ??= error; firstStackTrace ??= stackTrace; - await _handleToolError(firstError, firstStackTrace, verbose, args, reportCrashes, getVersion); + await _handleToolError(firstError!, firstStackTrace, verbose, args, reportCrashes!, getVersion); }); }, overrides: overrides); } Future _handleToolError( - dynamic error, - StackTrace stackTrace, + Object error, + StackTrace? stackTrace, bool verbose, List args, bool reportCrashes, @@ -102,7 +102,7 @@ Future _handleToolError( return _exit(64); } else if (error is ToolExit) { if (error.message != null) { - globals.printError(error.message); + globals.printError(error.message!); } if (verbose) { globals.printError('\n$stackTrace\n'); @@ -138,7 +138,7 @@ Future _handleToolError( ); await crashReportSender.sendReport( error: error, - stackTrace: stackTrace, + stackTrace: stackTrace!, getFlutterVersion: getFlutterVersion, command: args.join(' '), ); @@ -159,17 +159,17 @@ Future _handleToolError( final CrashDetails details = CrashDetails( command: _crashCommand(args), error: error, - stackTrace: stackTrace, + stackTrace: stackTrace!, doctorText: doctorText, ); final File file = await _createLocalCrashReport(details); - await globals.crashReporter.informUser(details, file); + await globals.crashReporter!.informUser(details, file); return _exit(1); // This catch catches all exceptions to ensure the message below is printed. - } catch (error) { // ignore: avoid_catches_without_on_clauses + } catch (error, st) { // ignore: avoid_catches_without_on_clauses globals.stdio.stderrWrite( - 'Unable to generate crash report due to secondary error: $error\n' + 'Unable to generate crash report due to secondary error: $error\n$st\n' '${globals.userMessages.flutterToolBugInstructions}\n', ); // Any exception thrown here (including one thrown by `_exit()`) will @@ -241,7 +241,7 @@ Future _exit(int code) async { } // Run shutdown hooks before flushing logs - await globals.shutdownHooks.runShutdownHooks(); + await globals.shutdownHooks!.runShutdownHooks(); final Completer completer = Completer(); diff --git a/packages/flutter_tools/lib/src/android/android_workflow.dart b/packages/flutter_tools/lib/src/android/android_workflow.dart index 675b47350858..20244ddb07d2 100644 --- a/packages/flutter_tools/lib/src/android/android_workflow.dart +++ b/packages/flutter_tools/lib/src/android/android_workflow.dart @@ -271,7 +271,7 @@ class AndroidValidator extends DoctorValidator { /// SDK have been accepted. class AndroidLicenseValidator extends DoctorValidator { AndroidLicenseValidator({ - required AndroidSdk androidSdk, + required AndroidSdk? androidSdk, required Platform platform, required OperatingSystemUtils operatingSystemUtils, required FileSystem fileSystem, @@ -291,7 +291,7 @@ class AndroidLicenseValidator extends DoctorValidator { _userMessages = userMessages, super('Android license subvalidator'); - final AndroidSdk _androidSdk; + final AndroidSdk? _androidSdk; final AndroidStudio? _androidStudio; final Stdio _stdio; final OperatingSystemUtils _operatingSystemUtils; @@ -309,13 +309,13 @@ class AndroidLicenseValidator extends DoctorValidator { final List messages = []; // Match pre-existing early termination behavior - if (_androidSdk == null || _androidSdk.latestVersion == null || - _androidSdk.validateSdkWellFormed().isNotEmpty || + if (_androidSdk == null || _androidSdk?.latestVersion == null || + _androidSdk!.validateSdkWellFormed().isNotEmpty || ! await _checkJavaVersionNoOutput()) { return ValidationResult(ValidationType.missing, messages); } - final String sdkVersionText = _userMessages.androidStatusInfo(_androidSdk.latestVersion!.buildToolsVersionName); + final String sdkVersionText = _userMessages.androidStatusInfo(_androidSdk!.latestVersion!.buildToolsVersionName); // Check for licenses. switch (await licensesAccepted) { @@ -392,8 +392,8 @@ class AndroidLicenseValidator extends DoctorValidator { try { final Process process = await _processManager.start( - [_androidSdk.sdkManagerPath!, '--licenses'], - environment: _androidSdk.sdkManagerEnv, + [_androidSdk!.sdkManagerPath!, '--licenses'], + environment: _androidSdk!.sdkManagerEnv, ); process.stdin.write('n\n'); // We expect logcat streams to occasionally contain invalid utf-8, @@ -432,8 +432,8 @@ class AndroidLicenseValidator extends DoctorValidator { try { final Process process = await _processManager.start( - [_androidSdk.sdkManagerPath!, '--licenses'], - environment: _androidSdk.sdkManagerEnv, + [_androidSdk!.sdkManagerPath!, '--licenses'], + environment: _androidSdk!.sdkManagerEnv, ); // The real stdin will never finish streaming. Pipe until the child process @@ -463,7 +463,7 @@ class AndroidLicenseValidator extends DoctorValidator { return exitCode == 0; } on ProcessException catch (e) { throwToolExit(_userMessages.androidCannotRunSdkManager( - _androidSdk.sdkManagerPath ?? '', + _androidSdk?.sdkManagerPath ?? '', e.toString(), _platform, )); @@ -471,7 +471,7 @@ class AndroidLicenseValidator extends DoctorValidator { } bool _canRunSdkManager() { - final String? sdkManagerPath = _androidSdk.sdkManagerPath; + final String? sdkManagerPath = _androidSdk?.sdkManagerPath; if (sdkManagerPath == null) { return false; } diff --git a/packages/flutter_tools/lib/src/android/application_package.dart b/packages/flutter_tools/lib/src/android/application_package.dart index cd0a5d5f0ced..236e71efdd8d 100644 --- a/packages/flutter_tools/lib/src/android/application_package.dart +++ b/packages/flutter_tools/lib/src/android/application_package.dart @@ -97,7 +97,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag /// Creates a new AndroidApk based on the information in the Android manifest. static Future fromAndroidProject( AndroidProject androidProject, { - required AndroidSdk androidSdk, + required AndroidSdk? androidSdk, required ProcessManager processManager, required UserMessages userMessages, required ProcessUtils processUtils, @@ -113,7 +113,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag // the application Id, so we need to look at what was actually built. return AndroidApk.fromApk( apkFile, - androidSdk: androidSdk, + androidSdk: androidSdk!, processManager: processManager, logger: logger, userMessages: userMessages, diff --git a/packages/flutter_tools/lib/src/base/utils.dart b/packages/flutter_tools/lib/src/base/utils.dart index 58830492322a..142b801f07cb 100644 --- a/packages/flutter_tools/lib/src/base/utils.dart +++ b/packages/flutter_tools/lib/src/base/utils.dart @@ -157,9 +157,9 @@ class SettingsFile { /// Given a data structure which is a Map of String to dynamic values, return /// the same structure (`Map`) with the correct runtime types. -Map? castStringKeyedMap(dynamic untyped) { +Map? castStringKeyedMap(Object? untyped) { final Map? map = untyped as Map?; - return map?.cast(); + return map?.cast(); } /// Smallest column that will be used for text wrapping. If the requested column diff --git a/packages/flutter_tools/lib/src/commands/attach.dart b/packages/flutter_tools/lib/src/commands/attach.dart index 288a02b1521d..bc50508185f4 100644 --- a/packages/flutter_tools/lib/src/commands/attach.dart +++ b/packages/flutter_tools/lib/src/commands/attach.dart @@ -2,11 +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 'dart:async'; -import 'package:meta/meta.dart'; import 'package:vm_service/vm_service.dart'; import '../android/android_device.dart'; @@ -123,7 +120,7 @@ class AttachCommand extends FlutterCommand { hotRunnerFactory ??= HotRunnerFactory(); } - HotRunnerFactory hotRunnerFactory; + HotRunnerFactory? hotRunnerFactory; @override final String name = 'attach'; @@ -148,22 +145,22 @@ known, it can be explicitly provided to attach via the command-line, e.g. @override final String category = FlutterCommandCategory.tools; - int get debugPort { - if (argResults['debug-port'] == null) { + int? get debugPort { + if (argResults!['debug-port'] == null) { return null; } try { - return int.parse(stringArgDeprecated('debug-port')); + return int.parse(stringArgDeprecated('debug-port')!); } on Exception catch (error) { throwToolExit('Invalid port for `--debug-port`: $error'); } } - Uri get debugUri { - if (argResults['debug-url'] == null) { + Uri? get debugUri { + if (argResults!['debug-url'] == null) { return null; } - final Uri uri = Uri.tryParse(stringArgDeprecated('debug-url')); + final Uri? uri = Uri.tryParse(stringArgDeprecated('debug-url')!); if (uri == null) { throwToolExit('Invalid `--debug-url`: ${stringArgDeprecated('debug-url')}'); } @@ -173,11 +170,11 @@ known, it can be explicitly provided to attach via the command-line, e.g. return uri; } - String get appId { + String? get appId { return stringArgDeprecated('app-id'); } - String get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); + String? get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); @override Future validateCommand() async { @@ -189,13 +186,13 @@ known, it can be explicitly provided to attach via the command-line, e.g. throwToolExit(null); } debugPort; - if (debugPort == null && debugUri == null && argResults.wasParsed(FlutterCommand.ipv6Flag)) { + if (debugPort == null && debugUri == null && argResults!.wasParsed(FlutterCommand.ipv6Flag)) { throwToolExit( 'When the --debug-port or --debug-url is unknown, this command determines ' 'the value of --ipv6 on its own.', ); } - if (debugPort == null && debugUri == null && argResults.wasParsed(FlutterCommand.observatoryPortOption)) { + if (debugPort == null && debugUri == null && argResults!.wasParsed(FlutterCommand.observatoryPortOption)) { throwToolExit( 'When the --debug-port or --debug-url is unknown, this command does not use ' 'the value of --observatory-port.', @@ -207,7 +204,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. } if (userIdentifier != null) { - final Device device = await findTargetDevice(); + final Device? device = await findTargetDevice(); if (device is! AndroidDevice) { throwToolExit('--${FlutterOptions.kDeviceUser} is only supported for Android'); } @@ -218,9 +215,9 @@ known, it can be explicitly provided to attach via the command-line, e.g. Future runCommand() async { await _validateArguments(); - final Device device = await findTargetDevice(); + final Device device = await (findTargetDevice() as FutureOr); - final Artifacts overrideArtifacts = device.artifactOverrides ?? globals.artifacts; + final Artifacts? overrideArtifacts = device.artifactOverrides ?? globals.artifacts; await context.run( body: () => _attachToDevice(device), overrides: { @@ -234,7 +231,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. Future _attachToDevice(Device device) async { final FlutterProject flutterProject = FlutterProject.current(); - final Daemon daemon = boolArgDeprecated('machine') + final Daemon? daemon = boolArgDeprecated('machine') ? Daemon( DaemonConnection( daemonStreams: DaemonStreams.fromStdio(globals.stdio, logger: globals.logger), @@ -247,20 +244,20 @@ known, it can be explicitly provided to attach via the command-line, e.g. ) : null; - Stream observatoryUri; - bool usesIpv6 = ipv6; + Stream? observatoryUri; + bool usesIpv6 = ipv6!; final String ipv6Loopback = InternetAddress.loopbackIPv6.address; final String ipv4Loopback = InternetAddress.loopbackIPv4.address; final String hostname = usesIpv6 ? ipv6Loopback : ipv4Loopback; if (debugPort == null && debugUri == null) { if (device is FuchsiaDevice) { - final String module = stringArgDeprecated('module'); + final String module = stringArgDeprecated('module')!; if (module == null) { throwToolExit("'--module' is required for attaching to a Fuchsia device"); } usesIpv6 = device.ipv6; - FuchsiaIsolateDiscoveryProtocol isolateDiscoveryProtocol; + FuchsiaIsolateDiscoveryProtocol? isolateDiscoveryProtocol; try { isolateDiscoveryProtocol = device.getIsolateDiscoveryProtocol(module); observatoryUri = Stream.value(await isolateDiscoveryProtocol.uri).asBroadcastStream(); @@ -273,9 +270,9 @@ known, it can be explicitly provided to attach via the command-line, e.g. rethrow; } } else if ((device is IOSDevice) || (device is IOSSimulator) || (device is MacOSDesignedForIPadDevice)) { - final Uri uriFromMdns = - await MDnsObservatoryDiscovery.instance.getObservatoryUri( - appId, + final Uri? uriFromMdns = + await MDnsObservatoryDiscovery.instance!.getObservatoryUri( + appId!, device, usesIpv6: usesIpv6, deviceVmservicePort: deviceVmservicePort, @@ -292,7 +289,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. // to find the service protocol. await device.getLogReader(includePastLogs: device is AndroidDevice), portForwarder: device.portForwarder, - ipv6: ipv6, + ipv6: ipv6!, devicePort: deviceVmservicePort, hostPort: hostVmservicePort, logger: globals.logger, @@ -308,7 +305,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. buildObservatoryUri( device, debugUri?.host ?? hostname, - debugPort ?? debugUri.port, + debugPort ?? debugUri!.port, hostVmservicePort, debugUri?.path, ) @@ -318,20 +315,20 @@ known, it can be explicitly provided to attach via the command-line, e.g. globals.terminal.usesTerminalUi = daemon == null; try { - int result; + int? result; if (daemon != null) { - final ResidentRunner runner = await createResidentRunner( + final ResidentRunner runner = await (createResidentRunner( observatoryUris: observatoryUri, device: device, flutterProject: flutterProject, usesIpv6: usesIpv6, - ); - AppInstance app; + ) as FutureOr); + late AppInstance app; try { app = await daemon.appDomain.launch( runner, - ({Completer connectionInfoCompleter, - Completer appStartedCompleter}) { + ({Completer? connectionInfoCompleter, + Completer? appStartedCompleter}) { return runner.attach( connectionInfoCompleter: connectionInfoCompleter, appStartedCompleter: appStartedCompleter, @@ -349,19 +346,19 @@ known, it can be explicitly provided to attach via the command-line, e.g. } on Exception catch (error) { throwToolExit(error.toString()); } - result = await app.runner.waitForAppToFinish(); + result = await app.runner!.waitForAppToFinish(); assert(result != null); return; } while (true) { - final ResidentRunner runner = await createResidentRunner( + final ResidentRunner runner = await (createResidentRunner( observatoryUris: observatoryUri, device: device, flutterProject: flutterProject, usesIpv6: usesIpv6, - ); + ) as FutureOr); final Completer onAppStart = Completer.sync(); - TerminalHandler terminalHandler; + TerminalHandler? terminalHandler; unawaited(onAppStart.future.whenComplete(() { terminalHandler = TerminalHandler( runner, @@ -396,18 +393,18 @@ known, it can be explicitly provided to attach via the command-line, e.g. } rethrow; } finally { - final List ports = device.portForwarder.forwardedPorts.toList(); + final List ports = device.portForwarder!.forwardedPorts.toList(); for (final ForwardedPort port in ports) { - await device.portForwarder.unforward(port); + await device.portForwarder!.unforward(port); } } } - Future createResidentRunner({ - @required Stream observatoryUris, - @required Device device, - @required FlutterProject flutterProject, - @required bool usesIpv6, + Future createResidentRunner({ + required Stream observatoryUris, + required Device device, + required FlutterProject flutterProject, + required bool usesIpv6, }) async { assert(observatoryUris != null); assert(device != null); @@ -418,7 +415,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. final FlutterDevice flutterDevice = await FlutterDevice.create( device, target: targetFile, - targetModel: TargetModel(stringArgDeprecated('target-model')), + targetModel: TargetModel(stringArgDeprecated('target-model')!), buildInfo: buildInfo, userIdentifier: userIdentifier, platform: globals.platform, @@ -433,11 +430,11 @@ known, it can be explicitly provided to attach via the command-line, e.g. ); return buildInfo.isDebug - ? hotRunnerFactory.build( + ? hotRunnerFactory!.build( flutterDevices, target: targetFile, debuggingOptions: debuggingOptions, - packagesFilePath: globalResults['packages'] as String, + packagesFilePath: globalResults!['packages'] as String?, projectRootPath: stringArgDeprecated('project-root'), dillOutputPath: stringArgDeprecated('output-dill'), ipv6: usesIpv6, @@ -455,19 +452,19 @@ known, it can be explicitly provided to attach via the command-line, e.g. } class HotRunnerFactory { - HotRunner build( + HotRunner? build( List devices, { - String target, - DebuggingOptions debuggingOptions, + required String target, + required DebuggingOptions debuggingOptions, bool benchmarkMode = false, - File applicationBinary, + File? applicationBinary, bool hostIsIde = false, - String projectRootPath, - String packagesFilePath, - String dillOutputPath, + String? projectRootPath, + String? packagesFilePath, + String? dillOutputPath, bool stayResident = true, bool ipv6 = false, - FlutterProject flutterProject, + FlutterProject? flutterProject, }) => HotRunner( devices, target: target, diff --git a/packages/flutter_tools/lib/src/commands/custom_devices.dart b/packages/flutter_tools/lib/src/commands/custom_devices.dart index 1d7cb0db6680..79b7b6778984 100644 --- a/packages/flutter_tools/lib/src/commands/custom_devices.dart +++ b/packages/flutter_tools/lib/src/commands/custom_devices.dart @@ -2,7 +2,7 @@ // 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'; @@ -32,14 +32,14 @@ typedef PrintFn = void Function(Object); class CustomDevicesCommand extends FlutterCommand { factory CustomDevicesCommand({ - @required CustomDevicesConfig customDevicesConfig, - @required OperatingSystemUtils operatingSystemUtils, - @required Terminal terminal, - @required Platform platform, - @required ProcessManager processManager, - @required FileSystem fileSystem, - @required Logger logger, - @required FeatureFlags featureFlags, + required CustomDevicesConfig customDevicesConfig, + required OperatingSystemUtils operatingSystemUtils, + required Terminal terminal, + required Platform platform, + required ProcessManager processManager, + required FileSystem fileSystem, + required Logger logger, + required FeatureFlags featureFlags, }) { return CustomDevicesCommand._common( customDevicesConfig: customDevicesConfig, @@ -55,14 +55,14 @@ class CustomDevicesCommand extends FlutterCommand { @visibleForTesting factory CustomDevicesCommand.test({ - @required CustomDevicesConfig customDevicesConfig, - @required OperatingSystemUtils operatingSystemUtils, - @required Terminal terminal, - @required Platform platform, - @required ProcessManager processManager, - @required FileSystem fileSystem, - @required Logger logger, - @required FeatureFlags featureFlags, + required CustomDevicesConfig customDevicesConfig, + required OperatingSystemUtils operatingSystemUtils, + required Terminal terminal, + required Platform platform, + required ProcessManager processManager, + required FileSystem fileSystem, + required Logger logger, + required FeatureFlags featureFlags, PrintFn usagePrintFn = print }) { return CustomDevicesCommand._common( @@ -79,14 +79,14 @@ class CustomDevicesCommand extends FlutterCommand { } CustomDevicesCommand._common({ - @required CustomDevicesConfig customDevicesConfig, - @required OperatingSystemUtils operatingSystemUtils, - @required Terminal terminal, - @required Platform platform, - @required ProcessManager processManager, - @required FileSystem fileSystem, - @required Logger logger, - @required FeatureFlags featureFlags, + required CustomDevicesConfig customDevicesConfig, + required OperatingSystemUtils operatingSystemUtils, + required Terminal terminal, + required Platform platform, + required ProcessManager processManager, + required FileSystem fileSystem, + required Logger logger, + required FeatureFlags featureFlags, PrintFn usagePrintFn = print, }) : assert(customDevicesConfig != null), assert(operatingSystemUtils != null), @@ -162,7 +162,9 @@ Requires the custom devices feature to be enabled. You can enable it using "flut String get category => FlutterCommandCategory.tools; @override - Future runCommand() async => null; + Future runCommand() async { + return FlutterCommandResult.success(); + } @override void printUsage() { @@ -175,15 +177,15 @@ Requires the custom devices feature to be enabled. You can enable it using "flut /// feature is enabled. abstract class CustomDevicesCommandBase extends FlutterCommand { CustomDevicesCommandBase({ - @required this.customDevicesConfig, - @required this.featureFlags, - @required this.fileSystem, - @required this.logger, + required this.customDevicesConfig, + required this.featureFlags, + required this.fileSystem, + required this.logger, }); @protected final CustomDevicesConfig customDevicesConfig; @protected final FeatureFlags featureFlags; - @protected final FileSystem fileSystem; + @protected final FileSystem? fileSystem; @protected final Logger logger; /// The path to the (potentially non-existing) backup of the config file. @@ -195,7 +197,7 @@ abstract class CustomDevicesCommandBase extends FlutterCommand { /// doesn't exist. (True otherwise) @protected bool backup() { - final File configFile = fileSystem.file(customDevicesConfig.configPath); + final File configFile = fileSystem!.file(customDevicesConfig.configPath); if (configFile.existsSync()) { configFile.copySync(configBackupPath); return true; @@ -219,14 +221,11 @@ abstract class CustomDevicesCommandBase extends FlutterCommand { class CustomDevicesListCommand extends CustomDevicesCommandBase { CustomDevicesListCommand({ - @required CustomDevicesConfig customDevicesConfig, - @required FeatureFlags featureFlags, - @required Logger logger, + required super.customDevicesConfig, + required super.featureFlags, + required super.logger, }) : super( - customDevicesConfig: customDevicesConfig, - featureFlags: featureFlags, - fileSystem: null, - logger: logger + fileSystem: null ); @override @@ -241,7 +240,7 @@ List the currently configured custom devices, both enabled and disabled, reachab Future runCommand() async { checkFeatureEnabled(); - List devices; + late List devices; try { devices = customDevicesConfig.devices; } on Exception { @@ -263,16 +262,11 @@ List the currently configured custom devices, both enabled and disabled, reachab class CustomDevicesResetCommand extends CustomDevicesCommandBase { CustomDevicesResetCommand({ - @required CustomDevicesConfig customDevicesConfig, - @required FeatureFlags featureFlags, - @required FileSystem fileSystem, - @required Logger logger, - }) : super( - customDevicesConfig: customDevicesConfig, - featureFlags: featureFlags, - fileSystem: fileSystem, - logger: logger - ); + required super.customDevicesConfig, + required super.featureFlags, + required FileSystem super.fileSystem, + required super.logger, + }); @override String get description => ''' @@ -291,7 +285,7 @@ If a file already exists at the backup location, it will be overwritten. final bool wasBackedUp = backup(); - ErrorHandlingFileSystem.deleteIfExists(fileSystem.file(customDevicesConfig.configPath)); + ErrorHandlingFileSystem.deleteIfExists(fileSystem!.file(customDevicesConfig.configPath)); customDevicesConfig.ensureFileExists(); logger.printStatus( @@ -306,24 +300,18 @@ If a file already exists at the backup location, it will be overwritten. class CustomDevicesAddCommand extends CustomDevicesCommandBase { CustomDevicesAddCommand({ - @required CustomDevicesConfig customDevicesConfig, - @required OperatingSystemUtils operatingSystemUtils, - @required Terminal terminal, - @required Platform platform, - @required FeatureFlags featureFlags, - @required ProcessManager processManager, - @required FileSystem fileSystem, - @required Logger logger, + required super.customDevicesConfig, + required OperatingSystemUtils operatingSystemUtils, + required Terminal terminal, + required Platform platform, + required super.featureFlags, + required ProcessManager processManager, + required FileSystem super.fileSystem, + required super.logger, }) : _operatingSystemUtils = operatingSystemUtils, _terminal = terminal, _platform = platform, - _processManager = processManager, - super( - customDevicesConfig: customDevicesConfig, - featureFlags: featureFlags, - fileSystem: fileSystem, - logger: logger - ) + _processManager = processManager { argParser.addFlag( _kCheck, @@ -379,7 +367,7 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { final Terminal _terminal; final Platform _platform; final ProcessManager _processManager; - StreamQueue inputs; + late StreamQueue inputs; @override String get description => 'Add a new device the custom devices config file.'; @@ -413,7 +401,7 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { result = false; } - final Directory temp = await fileSystem.systemTempDirectory.createTemp(); + final Directory temp = await fileSystem!.systemTempDirectory.createTemp(); try { final bool ok = await device.tryInstall( @@ -445,8 +433,8 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { if (config.usesPortForwarding) { final CustomDevicePortForwarder portForwarder = CustomDevicePortForwarder( deviceName: device.name, - forwardPortCommand: config.forwardPortCommand, - forwardPortSuccessRegex: config.forwardPortSuccessRegex, + forwardPortCommand: config.forwardPortCommand!, + forwardPortSuccessRegex: config.forwardPortSuccessRegex!, processManager: _processManager, logger: logger, ); @@ -455,7 +443,7 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { // find a random port we can forward final int port = await _operatingSystemUtils.findFreePort(); - final ForwardedPort forwardedPort = await portForwarder.tryForward(port, port); + final ForwardedPort forwardedPort = await (portForwarder.tryForward(port, port) as FutureOr); if (forwardedPort == null) { _printConfigCheckingError("Couldn't forward test port $port from device.",); result = false; @@ -482,8 +470,8 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { /// /// Only check if `--check` is explicitly specified. (Don't check by default) Future runNonInteractively() async { - final String jsonStr = stringArgDeprecated(_kJson); - final bool shouldCheck = boolArgDeprecated(_kCheck) ?? false; + final String jsonStr = stringArgDeprecated(_kJson)!; + final bool shouldCheck = boolArgDeprecated(_kCheck); dynamic json; try { @@ -492,7 +480,7 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { throwToolExit('Could not decode json: $e'); } - CustomDeviceConfig config; + late CustomDeviceConfig config; try { config = CustomDeviceConfig.fromJson(json); } on CustomDeviceRevivalException catch (e) { @@ -518,12 +506,12 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { bool _isValidIpAddr(String s) => InternetAddress.tryParse(s) != null; /// Ask the user to input a string. - Future askForString( + Future askForString( String name, { - String description, - String example, - String defaultsTo, - Future Function(String) validator, + String? description, + String? example, + String? defaultsTo, + Future Function(String)? validator, }) async { String msg = description ?? name; @@ -555,7 +543,7 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { /// Ask the user for a y(es) / n(o) or empty input. Future askForBool( String name, { - String description, + String? description, bool defaultsTo = true, }) async { final String defaultsToStr = defaultsTo == true ? '[Y/n]' : '[y/N]'; @@ -591,7 +579,7 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { /// Run interactively (with user prompts), the target device should be /// connected to via ssh. Future runInteractivelySsh() async { - final bool shouldCheck = boolArgDeprecated(_kCheck) ?? true; + final bool shouldCheck = boolArgDeprecated(_kCheck); // Listen to the keystrokes stream as late as possible, since it's a // single-subscription stream apparently. @@ -610,61 +598,61 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { inputs = StreamQueue(nonClosingKeystrokes.stream); - final String id = await askForString( + final String id = await (askForString( 'id', description: 'Please enter the id you want to device to have. Must contain only ' 'alphanumeric or underscore characters.', example: 'pi', validator: (String s) async => RegExp(r'^\w+$').hasMatch(s), - ); + ) as FutureOr); - final String label = await askForString( + final String label = await (askForString( 'label', description: 'Please enter the label of the device, which is a slightly more verbose ' 'name for the device.', example: 'Raspberry Pi', - ); + ) as FutureOr); - final String sdkNameAndVersion = await askForString( + final String sdkNameAndVersion = await (askForString( 'SDK name and version', example: 'Raspberry Pi 4 Model B+', - ); + ) as FutureOr); final bool enabled = await askForBool( 'enabled', description: 'Should the device be enabled?', ); - final String targetStr = await askForString( + final String targetStr = await (askForString( 'target', description: 'Please enter the hostname or IPv4/v6 address of the device.', example: 'raspberrypi', validator: (String s) async => _isValidHostname(s) || _isValidIpAddr(s) - ); + ) as FutureOr); - final InternetAddress targetIp = InternetAddress.tryParse(targetStr); + final InternetAddress? targetIp = InternetAddress.tryParse(targetStr); final bool useIp = targetIp != null; final bool ipv6 = useIp && targetIp.type == InternetAddressType.IPv6; final InternetAddress loopbackIp = ipv6 ? InternetAddress.loopbackIPv6 : InternetAddress.loopbackIPv4; - final String username = await askForString( + final String username = await (askForString( 'username', description: 'Please enter the username used for ssh-ing into the remote device.', example: 'pi', defaultsTo: 'no username', - ); + ) as FutureOr); - final String remoteRunDebugCommand = await askForString( + final String remoteRunDebugCommand = await (askForString( 'run command', description: 'Please enter the command executed on the remote device for starting ' r'the app. "/tmp/${appName}" is the path to the asset bundle.', example: r'flutter-pi /tmp/${appName}' - ); + ) as FutureOr); final bool usePortForwarding = await askForBool( 'use port forwarding', @@ -675,12 +663,12 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { 'not using port forwarding.', ); - final String screenshotCommand = await askForString( + final String screenshotCommand = await (askForString( 'screenshot command', description: 'Enter the command executed on the remote device for taking a screenshot.', example: r"fbgrab /tmp/screenshot.png && cat /tmp/screenshot.png | base64 | tr -d ' \n\t'", defaultsTo: 'no screenshotting support', - ); + ) as FutureOr); // SSH expects IPv6 addresses to use the bracket syntax like URIs do too, // but the IPv6 the user enters is a raw IPv6 address, so we need to wrap it. @@ -777,7 +765,6 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { targetStr, ], explicitPingSuccessRegex: true, - pingSuccessRegex: null ); } else { throw UnsupportedError('Unsupported operating system'); @@ -815,16 +802,11 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase { class CustomDevicesDeleteCommand extends CustomDevicesCommandBase { CustomDevicesDeleteCommand({ - @required CustomDevicesConfig customDevicesConfig, - @required FeatureFlags featureFlags, - @required FileSystem fileSystem, - @required Logger logger, - }) : super( - customDevicesConfig: customDevicesConfig, - featureFlags: featureFlags, - fileSystem: fileSystem, - logger: logger - ); + required super.customDevicesConfig, + required super.featureFlags, + required FileSystem super.fileSystem, + required super.logger, + }); @override String get description => ''' @@ -838,7 +820,7 @@ Delete a device from the config file. Future runCommand() async { checkFeatureEnabled(); - final String id = globalResults['device-id'] as String; + final String id = globalResults!['device-id'] as String; if (!customDevicesConfig.contains(id)) { throwToolExit('Couldn\'t find device with id "$id" in config at "${customDevicesConfig.configPath}"'); } diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index d0a3228f2f87..4566c93b3529 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.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 'package:async/async.dart'; @@ -66,10 +64,10 @@ class DaemonCommand extends FlutterCommand { @override Future runCommand() async { - if (argResults['listen-on-tcp-port'] != null) { - int port; + if (argResults!['listen-on-tcp-port'] != null) { + int? port; try { - port = int.parse(stringArgDeprecated('listen-on-tcp-port')); + port = int.parse(stringArgDeprecated('listen-on-tcp-port')!); } on FormatException catch (error) { throwToolExit('Invalid port for `--listen-on-tcp-port`: $error'); } @@ -108,17 +106,17 @@ class _DaemonServer { this.notifyingLogger, }); - final int port; + final int? port; /// Stdout logger used to print general server-related errors. - final Logger logger; + final Logger? logger; // Logger that sends the message to the other end of daemon connection. - final NotifyingLogger notifyingLogger; + final NotifyingLogger? notifyingLogger; Future run() async { - final ServerSocket serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, port); - logger.printStatus('Daemon server listening on ${serverSocket.port}'); + final ServerSocket serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, port!); + logger!.printStatus('Daemon server listening on ${serverSocket.port}'); final StreamSubscription subscription = serverSocket.listen( (Socket socket) async { @@ -126,13 +124,13 @@ class _DaemonServer { // reset, we will receive an uncatchable exception. // https://github.com/dart-lang/sdk/issues/25518 final Future socketDone = socket.done.catchError((dynamic error, StackTrace stackTrace) { - logger.printError('Socket error: $error'); - logger.printTrace('$stackTrace'); + logger!.printError('Socket error: $error'); + logger!.printTrace('$stackTrace'); }); final Daemon daemon = Daemon( DaemonConnection( - daemonStreams: DaemonStreams.fromSocket(socket, logger: logger), - logger: logger, + daemonStreams: DaemonStreams.fromSocket(socket, logger: logger!), + logger: logger!, ), notifyingLogger: notifyingLogger, ); @@ -147,8 +145,8 @@ class _DaemonServer { } } -typedef CommandHandler = Future Function(Map args); -typedef CommandHandlerWithBinary = Future Function(Map args, Stream> binary); +typedef CommandHandler = Future? Function(Map args); +typedef CommandHandlerWithBinary = Future Function(Map args, Stream>? binary); class Daemon { Daemon( @@ -178,15 +176,15 @@ class Daemon { final DaemonConnection connection; - DaemonDomain daemonDomain; - AppDomain appDomain; - DeviceDomain deviceDomain; - EmulatorDomain emulatorDomain; - DevToolsDomain devToolsDomain; - ProxyDomain proxyDomain; - StreamSubscription _commandSubscription; + late DaemonDomain daemonDomain; + late AppDomain appDomain; + late DeviceDomain deviceDomain; + EmulatorDomain? emulatorDomain; + DevToolsDomain? devToolsDomain; + late ProxyDomain proxyDomain; + StreamSubscription? _commandSubscription; - final NotifyingLogger notifyingLogger; + final NotifyingLogger? notifyingLogger; final bool logToStdout; final Completer _onExitCompleter = Completer(); @@ -203,7 +201,7 @@ class Daemon { // {id, method, params} // [id] is an opaque type to us. - final dynamic id = request.data['id']; + final Object? id = request.data['id']; if (id == null) { globals.stdio.stderrWrite('no id for request: $request\n'); @@ -211,7 +209,7 @@ class Daemon { } try { - final String method = request.data['method'] as String; + final String method = request.data['method']! as String; assert(method != null); if (!method.contains('.')) { throw DaemonException('method not understood: $method'); @@ -223,13 +221,13 @@ class Daemon { throw DaemonException('no domain for method: $method'); } - _domainMap[prefix].handleCommand(name, id, castStringKeyedMap(request.data['params']) ?? const {}, request.binary); + _domainMap[prefix]!.handleCommand(name, id, castStringKeyedMap(request.data['params']) ?? const {}, request.binary); } on Exception catch (error, trace) { connection.sendErrorResponse(id, _toJsonable(error), trace); } } - Future shutdown({ dynamic error }) async { + Future shutdown({ Object? error }) async { await devToolsDomain?.dispose(); await _commandSubscription?.cancel(); await connection.dispose(); @@ -270,12 +268,12 @@ abstract class Domain { @override String toString() => name; - void handleCommand(String command, dynamic id, Map args, Stream> binary) { + void handleCommand(String command, Object id, Map args, Stream>? binary) { Future.sync(() { if (_handlers.containsKey(command)) { - return _handlers[command](args); + return _handlers[command]!(args); } else if (_handlersWithBinary.containsKey(command)) { - return _handlersWithBinary[command](args, binary); + return _handlersWithBinary[command]!(args, binary); } throw DaemonException('command not understood: $name.$command'); }).then((dynamic result) { @@ -285,11 +283,11 @@ abstract class Domain { }); } - void sendEvent(String name, [ dynamic args, List binary ]) { + void sendEvent(String name, [ dynamic args, List? binary ]) { daemon.connection.sendEvent(name, _toJsonable(args), binary); } - String _getStringArg(Map args, String name, { bool required = false }) { + String? _getStringArg(Map args, String name, { bool required = false }) { if (required && !args.containsKey(name)) { throw DaemonException('$name is required'); } @@ -297,10 +295,10 @@ abstract class Domain { if (val != null && val is! String) { throw DaemonException('$name is not a String'); } - return val as String; + return val as String?; } - bool _getBoolArg(Map args, String name, { bool required = false }) { + bool? _getBoolArg(Map args, String name, { bool required = false }) { if (required && !args.containsKey(name)) { throw DaemonException('$name is required'); } @@ -308,10 +306,10 @@ abstract class Domain { if (val != null && val is! bool) { throw DaemonException('$name is not a bool'); } - return val as bool; + return val as bool?; } - int _getIntArg(Map args, String name, { bool required = false }) { + int? _getIntArg(Map args, String name, { bool required = false }) { if (required && !args.containsKey(name)) { throw DaemonException('$name is required'); } @@ -319,7 +317,7 @@ abstract class Domain { if (val != null && val is! int) { throw DaemonException('$name is not an int'); } - return val as int; + return val as int?; } Future dispose() async { } @@ -342,7 +340,7 @@ class DaemonDomain extends Domain { }, ); - _subscription = daemon.notifyingLogger.onMessage.listen((LogMessage message) { + _subscription = daemon.notifyingLogger!.onMessage.listen((LogMessage message) { if (daemon.logToStdout) { if (message.level == 'status') { // We use `print()` here instead of `stdout.writeln()` in order to @@ -374,7 +372,7 @@ class DaemonDomain extends Domain { }); } - StreamSubscription _subscription; + StreamSubscription? _subscription; Future version(Map args) { return Future.value(protocolVersion); @@ -411,7 +409,7 @@ class DaemonDomain extends Domain { /// as whether command line tools are installed or whether the host platform /// is correct. Future> getSupportedPlatforms(Map args) async { - final String projectRoot = _getStringArg(args, 'projectRoot', required: true); + final String? projectRoot = _getStringArg(args, 'projectRoot', required: true); final List result = []; try { final FlutterProject flutterProject = FlutterProject.fromDirectory(globals.fs.directory(projectRoot)); @@ -461,8 +459,8 @@ class DaemonDomain extends Domain { } typedef RunOrAttach = Future Function({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, }); /// This domain responds to methods like [start] and [stop]. @@ -488,17 +486,17 @@ class AppDomain extends Domain { Device device, String projectDirectory, String target, - String route, + String? route, DebuggingOptions options, bool enableHotReload, { - File applicationBinary, - @required bool trackWidgetCreation, - String projectRootPath, - String packagesFilePath, - String dillOutputPath, + File? applicationBinary, + required bool trackWidgetCreation, + String? projectRootPath, + String? packagesFilePath, + String? dillOutputPath, bool ipv6 = false, bool multidexEnabled = false, - String isolateFilter, + String? isolateFilter, bool machine = true, }) async { if (!await device.supportsRuntimeMode(options.buildInfo.mode)) { @@ -523,14 +521,14 @@ class AppDomain extends Domain { ResidentRunner runner; if (await device.targetPlatform == TargetPlatform.web_javascript) { - runner = webRunnerFactory.createWebRunner( + runner = webRunnerFactory!.createWebRunner( flutterDevice, flutterProject: flutterProject, target: target, debuggingOptions: options, ipv6: ipv6, stayResident: true, - urlTunneller: options.webEnableExposeUrl ? daemon.daemonDomain.exposeUrl : null, + urlTunneller: options.webEnableExposeUrl! ? daemon.daemonDomain.exposeUrl : null, machine: machine, usage: globals.flutterUsage, systemClock: globals.systemClock, @@ -565,8 +563,8 @@ class AppDomain extends Domain { return launch( runner, ({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, }) { return runner.run( connectionInfoCompleter: connectionInfoCompleter, @@ -588,7 +586,7 @@ class AppDomain extends Domain { ResidentRunner runner, RunOrAttach runOrAttach, Device device, - String projectDirectory, + String? projectDirectory, bool enableHotReload, Directory cwd, LaunchMode launchMode, @@ -610,7 +608,7 @@ class AppDomain extends Domain { 'launchMode': launchMode.toString(), }); - Completer connectionInfoCompleter; + Completer? connectionInfoCompleter; if (runner.debuggingEnabled) { connectionInfoCompleter = Completer(); @@ -620,7 +618,7 @@ class AppDomain extends Domain { (DebugConnectionInfo info) { final Map params = { // The web vmservice proxy does not have an http address. - 'port': info.httpUri?.port ?? info.wsUri.port, + 'port': info.httpUri?.port ?? info.wsUri!.port, 'wsUri': info.wsUri.toString(), }; if (info.baseUri != null) { @@ -664,16 +662,16 @@ class AppDomain extends Domain { final int _hotReloadDebounceDurationMs = 50; - Future restart(Map args) async { - final String appId = _getStringArg(args, 'appId', required: true); + Future? restart(Map args) async { + final String? appId = _getStringArg(args, 'appId', required: true); final bool fullRestart = _getBoolArg(args, 'fullRestart') ?? false; final bool pauseAfterRestart = _getBoolArg(args, 'pause') ?? false; - final String restartReason = _getStringArg(args, 'reason'); + final String? restartReason = _getStringArg(args, 'reason'); final bool debounce = _getBoolArg(args, 'debounce') ?? false; // This is an undocumented parameter used for integration tests. - final int debounceDurationOverrideMs = _getIntArg(args, 'debounceDurationOverrideMs'); + final int? debounceDurationOverrideMs = _getIntArg(args, 'debounceDurationOverrideMs'); - final AppInstance app = _getApp(appId); + final AppInstance? app = _getApp(appId); if (app == null) { throw DaemonException("app '$appId' not found"); } @@ -689,7 +687,7 @@ class AppDomain extends Domain { pause: pauseAfterRestart, reason: restartReason); }, - ); + )!; } /// Debounce and queue reload actions. @@ -699,11 +697,11 @@ class AppDomain extends Domain { /// and all return the same result. If an action is requested after an identical /// action has already started, it will be queued and run again once the first /// action completes. - Future _queueAndDebounceReloadAction( + Future? _queueAndDebounceReloadAction( AppInstance app, OperationType operationType, bool debounce, - int debounceDurationOverrideMs, + int? debounceDurationOverrideMs, Future Function() action, ) { final Duration debounceDuration = debounce @@ -727,39 +725,40 @@ class AppDomain extends Domain { /// "method":"ext.flutter.platformOverride" /// } Future> callServiceExtension(Map args) async { - final String appId = _getStringArg(args, 'appId', required: true); - final String methodName = _getStringArg(args, 'methodName'); - final Map params = args['params'] == null ? {} : castStringKeyedMap(args['params']); + final String? appId = _getStringArg(args, 'appId', required: true); + final String methodName = _getStringArg(args, 'methodName')!; + final Map? params = args['params'] == null ? {} : castStringKeyedMap(args['params']); - final AppInstance app = _getApp(appId); + final AppInstance? app = _getApp(appId); if (app == null) { throw DaemonException("app '$appId' not found"); } - final FlutterDevice device = app.runner.flutterDevices.first; - final List views = await device.vmService.getFlutterViews(); - final Map result = await device - .vmService + final FlutterDevice device = app.runner!.flutterDevices.first!; + final List views = await device.vmService!.getFlutterViews(); + final Map? result = await device + .vmService! .invokeFlutterExtensionRpcRaw( methodName, args: params, isolateId: views - .first.uiIsolate.id + .first.uiIsolate!.id! ); if (result == null) { throw DaemonException('method not available: $methodName'); } if (result.containsKey('error')) { - throw result['error']; + // ignore: only_throw_errors + throw result['error']! as Object; } return result; } Future stop(Map args) async { - final String appId = _getStringArg(args, 'appId', required: true); + final String? appId = _getStringArg(args, 'appId', required: true); - final AppInstance app = _getApp(appId); + final AppInstance? app = _getApp(appId); if (app == null) { throw DaemonException("app '$appId' not found"); } @@ -776,9 +775,9 @@ class AppDomain extends Domain { } Future detach(Map args) async { - final String appId = _getStringArg(args, 'appId', required: true); + final String? appId = _getStringArg(args, 'appId', required: true); - final AppInstance app = _getApp(appId); + final AppInstance? app = _getApp(appId); if (app == null) { throw DaemonException("app '$appId' not found"); } @@ -794,11 +793,16 @@ class AppDomain extends Domain { ); } - AppInstance _getApp(String id) { - return _apps.firstWhere((AppInstance app) => app.id == id, orElse: () => null); + AppInstance? _getApp(String? id) { + for (final AppInstance app in _apps) { + if (app.id == id) { + return app; + } + } + return null; } - void _sendAppEvent(AppInstance app, String name, [ Map args ]) { + void _sendAppEvent(AppInstance app, String name, [ Map? args ]) { sendEvent('app.$name', { 'appId': app.id, ...?args, @@ -830,12 +834,12 @@ class DeviceDomain extends Domain { // Use the device manager discovery so that client provided device types // are usable via the daemon protocol. - globals.deviceManager.deviceDiscoverers.forEach(addDeviceDiscoverer); + globals.deviceManager!.deviceDiscoverers.forEach(addDeviceDiscoverer); } /// An incrementing number used to generate unique ids. int _id = 0; - final Map _applicationPackages = {}; + final Map _applicationPackages = {}; final Map _logReaders = {}; void addDeviceDiscoverer(DeviceDiscovery discoverer) { @@ -856,7 +860,7 @@ class DeviceDomain extends Domain { return (Device device) { _serializeDeviceEvents = _serializeDeviceEvents.then((_) async { try { - final Map response = await _deviceToMap(device); + final Map response = await _deviceToMap(device); sendEvent(eventName, response); } on Exception catch (err) { globals.printError('$err'); @@ -869,7 +873,7 @@ class DeviceDomain extends Domain { /// Return a list of the current devices, with each device represented as a map /// of properties (id, name, platform, ...). - Future>> getDevices([ Map args ]) async { + Future>> getDevices([ Map? args ]) async { return >[ for (final PollingDeviceDiscovery discoverer in _discoverers) for (final Device device in await discoverer.devices) @@ -878,7 +882,7 @@ class DeviceDomain extends Domain { } /// Return a list of the current devices, discarding existing cache of devices. - Future>> discoverDevices([ Map args ]) async { + Future>> discoverDevices([ Map? args ]) async { return >[ for (final PollingDeviceDiscovery discoverer in _discoverers) for (final Device device in await discoverer.discoverDevices()) @@ -902,50 +906,50 @@ class DeviceDomain extends Domain { /// Forward a host port to a device port. Future> forward(Map args) async { - final String deviceId = _getStringArg(args, 'deviceId', required: true); - final int devicePort = _getIntArg(args, 'devicePort', required: true); - int hostPort = _getIntArg(args, 'hostPort'); + final String? deviceId = _getStringArg(args, 'deviceId', required: true); + final int devicePort = _getIntArg(args, 'devicePort', required: true)!; + int? hostPort = _getIntArg(args, 'hostPort'); - final Device device = await daemon.deviceDomain._getDevice(deviceId); + final Device? device = await daemon.deviceDomain._getDevice(deviceId); if (device == null) { throw DaemonException("device '$deviceId' not found"); } - hostPort = await device.portForwarder.forward(devicePort, hostPort: hostPort); + hostPort = await device.portForwarder!.forward(devicePort, hostPort: hostPort); return {'hostPort': hostPort}; } /// Removes a forwarded port. Future unforward(Map args) async { - final String deviceId = _getStringArg(args, 'deviceId', required: true); - final int devicePort = _getIntArg(args, 'devicePort', required: true); - final int hostPort = _getIntArg(args, 'hostPort', required: true); + final String? deviceId = _getStringArg(args, 'deviceId', required: true); + final int devicePort = _getIntArg(args, 'devicePort', required: true)!; + final int hostPort = _getIntArg(args, 'hostPort', required: true)!; - final Device device = await daemon.deviceDomain._getDevice(deviceId); + final Device? device = await daemon.deviceDomain._getDevice(deviceId); if (device == null) { throw DaemonException("device '$deviceId' not found"); } - return device.portForwarder.unforward(ForwardedPort(hostPort, devicePort)); + return device.portForwarder!.unforward(ForwardedPort(hostPort, devicePort)); } /// Returns whether a device supports runtime mode. Future supportsRuntimeMode(Map args) async { - final String deviceId = _getStringArg(args, 'deviceId', required: true); - final Device device = await daemon.deviceDomain._getDevice(deviceId); + final String? deviceId = _getStringArg(args, 'deviceId', required: true); + final Device? device = await daemon.deviceDomain._getDevice(deviceId); if (device == null) { throw DaemonException("device '$deviceId' not found"); } - final String buildMode = _getStringArg(args, 'buildMode', required: true); + final String buildMode = _getStringArg(args, 'buildMode', required: true)!; return await device.supportsRuntimeMode(getBuildModeForName(buildMode)); } /// Creates an application package from a file in the temp directory. Future uploadApplicationPackage(Map args) async { - final TargetPlatform targetPlatform = getTargetPlatformForName(_getStringArg(args, 'targetPlatform', required: true)); - final File applicationBinary = daemon.proxyDomain.tempDirectory.childFile(_getStringArg(args, 'applicationBinary', required: true)); - final ApplicationPackage applicationPackage = await ApplicationPackageFactory.instance.getPackageForPlatform( + final TargetPlatform targetPlatform = getTargetPlatformForName(_getStringArg(args, 'targetPlatform', required: true)!); + final File applicationBinary = daemon.proxyDomain.tempDirectory.childFile(_getStringArg(args, 'applicationBinary', required: true)!); + final ApplicationPackage? applicationPackage = await ApplicationPackageFactory.instance!.getPackageForPlatform( targetPlatform, applicationBinary: applicationBinary, ); @@ -956,13 +960,13 @@ class DeviceDomain extends Domain { /// Starts the log reader on the device. Future startLogReader(Map args) async { - final String deviceId = _getStringArg(args, 'deviceId', required: true); - final Device device = await daemon.deviceDomain._getDevice(deviceId); + final String? deviceId = _getStringArg(args, 'deviceId', required: true); + final Device? device = await daemon.deviceDomain._getDevice(deviceId); if (device == null) { throw DaemonException("device '$deviceId' not found"); } - final String applicationPackageId = _getStringArg(args, 'applicationPackageId'); - final ApplicationPackage applicationPackage = applicationPackageId != null ? _applicationPackages[applicationPackageId] : null; + final String? applicationPackageId = _getStringArg(args, 'applicationPackageId'); + final ApplicationPackage? applicationPackage = applicationPackageId != null ? _applicationPackages[applicationPackageId] : null; final String id = '${deviceId}_${_id++}'; final DeviceLogReader logReader = await device.getLogReader(app: applicationPackage); @@ -975,32 +979,32 @@ class DeviceDomain extends Domain { /// Stops a log reader that was previously started. Future stopLogReader(Map args) async { - final String id = _getStringArg(args, 'id', required: true); + final String? id = _getStringArg(args, 'id', required: true); _logReaders.remove(id)?.dispose(); } /// Starts an app on a device. Future> startApp(Map args) async { - final String deviceId = _getStringArg(args, 'deviceId', required: true); - final Device device = await daemon.deviceDomain._getDevice(deviceId); + final String? deviceId = _getStringArg(args, 'deviceId', required: true); + final Device? device = await daemon.deviceDomain._getDevice(deviceId); if (device == null) { throw DaemonException("device '$deviceId' not found"); } - final String applicationPackageId = _getStringArg(args, 'applicationPackageId', required: true); - final ApplicationPackage applicationPackage = _applicationPackages[applicationPackageId]; + final String? applicationPackageId = _getStringArg(args, 'applicationPackageId', required: true); + final ApplicationPackage applicationPackage = _applicationPackages[applicationPackageId!]!; final LaunchResult result = await device.startApp( applicationPackage, debuggingOptions: DebuggingOptions.fromJson( - castStringKeyedMap(args['debuggingOptions']), + castStringKeyedMap(args['debuggingOptions'])!, // We are using prebuilts, build info does not matter here. BuildInfo.debug, ), mainPath: _getStringArg(args, 'mainPath'), route: _getStringArg(args, 'route'), - platformArgs: castStringKeyedMap(args['platformArgs']), - prebuiltApplication: _getBoolArg(args, 'prebuiltApplication'), - ipv6: _getBoolArg(args, 'ipv6'), + platformArgs: castStringKeyedMap(args['platformArgs']) ?? const {}, + prebuiltApplication: _getBoolArg(args, 'prebuiltApplication') ?? false, + ipv6: _getBoolArg(args, 'ipv6') ?? false, userIdentifier: _getStringArg(args, 'userIdentifier'), ); return { @@ -1011,13 +1015,13 @@ class DeviceDomain extends Domain { /// Stops an app. Future stopApp(Map args) async { - final String deviceId = _getStringArg(args, 'deviceId', required: true); - final Device device = await daemon.deviceDomain._getDevice(deviceId); + final String? deviceId = _getStringArg(args, 'deviceId', required: true); + final Device? device = await daemon.deviceDomain._getDevice(deviceId); if (device == null) { throw DaemonException("device '$deviceId' not found"); } - final String applicationPackageId = _getStringArg(args, 'applicationPackageId', required: true); - final ApplicationPackage applicationPackage = _applicationPackages[applicationPackageId]; + final String? applicationPackageId = _getStringArg(args, 'applicationPackageId', required: true); + final ApplicationPackage applicationPackage = _applicationPackages[applicationPackageId!]!; return device.stopApp( applicationPackage, userIdentifier: _getStringArg(args, 'userIdentifier'), @@ -1025,9 +1029,9 @@ class DeviceDomain extends Domain { } /// Takes a screenshot. - Future takeScreenshot(Map args) async { - final String deviceId = _getStringArg(args, 'deviceId', required: true); - final Device device = await daemon.deviceDomain._getDevice(deviceId); + Future takeScreenshot(Map args) async { + final String? deviceId = _getStringArg(args, 'deviceId', required: true); + final Device? device = await daemon.deviceDomain._getDevice(deviceId); if (device == null) { throw DaemonException("device '$deviceId' not found"); } @@ -1051,9 +1055,15 @@ class DeviceDomain extends Domain { } /// Return the device matching the deviceId field in the args. - Future _getDevice(String deviceId) async { + Future _getDevice(String? deviceId) async { for (final PollingDeviceDiscovery discoverer in _discoverers) { - final Device device = (await discoverer.devices).firstWhere((Device device) => device.id == deviceId, orElse: () => null); + final List devices = await discoverer.devices; + Device? device; + for (final Device localDevice in devices) { + if (localDevice.id == deviceId) { + device = localDevice; + } + } if (device != null) { return device; } @@ -1067,11 +1077,11 @@ class DevToolsDomain extends Domain { registerHandler('serve', serve); } - DevtoolsLauncher _devtoolsLauncher; + DevtoolsLauncher? _devtoolsLauncher; - Future> serve([ Map args ]) async { + Future> serve([ Map? args ]) async { _devtoolsLauncher ??= DevtoolsLauncher.instance; - final DevToolsServerAddress server = await _devtoolsLauncher.serve(); + final DevToolsServerAddress? server = await _devtoolsLauncher?.serve(); return{ 'host': server?.host, 'port': server?.port, @@ -1111,8 +1121,8 @@ Map _emulatorToMap(Emulator emulator) { return { 'id': emulator.id, 'name': emulator.name, - 'category': emulator.category?.toString(), - 'platformType': emulator.platformType?.toString(), + 'category': emulator.category.toString(), + 'platformType': emulator.platformType.toString(), }; } @@ -1123,7 +1133,7 @@ Map _operationResultToMap(OperationResult result) { }; } -dynamic _toJsonable(dynamic obj) { +Object? _toJsonable(dynamic obj) { if (obj is String || obj is int || obj is bool || obj is Map || obj is List || obj == null) { return obj; } @@ -1137,7 +1147,7 @@ dynamic _toJsonable(dynamic obj) { } class NotifyingLogger extends DelegatingLogger { - NotifyingLogger({ @required this.verbose, @required Logger parent }) : super(parent) { + NotifyingLogger({ required this.verbose, required Logger parent }) : super(parent) { _messageController = StreamController.broadcast( onListen: _onListen, ); @@ -1145,7 +1155,7 @@ class NotifyingLogger extends DelegatingLogger { final bool verbose; final List messageBuffer = []; - StreamController _messageController; + late StreamController _messageController; void _onListen() { if (messageBuffer.isNotEmpty) { @@ -1159,12 +1169,12 @@ class NotifyingLogger extends DelegatingLogger { @override void printError( String message, { - StackTrace stackTrace, - bool emphasis = false, - TerminalColor color, - int indent, - int hangingIndent, - bool wrap, + StackTrace? stackTrace, + bool? emphasis = false, + TerminalColor? color, + int? indent, + int? hangingIndent, + bool? wrap, }) { _sendMessage(LogMessage('error', message, stackTrace)); } @@ -1172,11 +1182,11 @@ class NotifyingLogger extends DelegatingLogger { @override void printWarning( String message, { - bool emphasis = false, - TerminalColor color, - int indent, - int hangingIndent, - bool wrap, + bool? emphasis = false, + TerminalColor? color, + int? indent, + int? hangingIndent, + bool? wrap, }) { _sendMessage(LogMessage('warning', message)); } @@ -1184,19 +1194,19 @@ class NotifyingLogger extends DelegatingLogger { @override void printStatus( String message, { - bool emphasis = false, - TerminalColor color, - bool newline = true, - int indent, - int hangingIndent, - bool wrap, + bool? emphasis = false, + TerminalColor? color, + bool? newline = true, + int? indent, + int? hangingIndent, + bool? wrap, }) { _sendMessage(LogMessage('status', message)); } @override void printBox(String message, { - String title, + String? title, }) { _sendMessage(LogMessage('status', title == null ? message : '$title: $message')); } @@ -1212,8 +1222,8 @@ class NotifyingLogger extends DelegatingLogger { @override Status startProgress( String message, { - @required Duration timeout, - String progressId, + Duration? timeout, + String? progressId, bool multilineOutput = false, bool includeTiming = true, int progressIndicatorPadding = kDefaultStatusPadding, @@ -1237,7 +1247,7 @@ class NotifyingLogger extends DelegatingLogger { } @override - void sendEvent(String name, [Map args]) { } + void sendEvent(String name, [Map? args]) { } @override bool get supportsColor => throw UnimplementedError(); @@ -1252,20 +1262,20 @@ class NotifyingLogger extends DelegatingLogger { /// A running application, started by this daemon. class AppInstance { - AppInstance(this.id, { this.runner, this.logToStdout = false, @required AppRunLogger logger }) + AppInstance(this.id, { this.runner, this.logToStdout = false, required AppRunLogger logger }) : _logger = logger; final String id; - final ResidentRunner runner; + final ResidentRunner? runner; final bool logToStdout; final AppRunLogger _logger; - Future restart({ bool fullRestart = false, bool pause = false, String reason }) { - return runner.restart(fullRestart: fullRestart, pause: pause, reason: reason); + Future restart({ bool fullRestart = false, bool pause = false, String? reason }) { + return runner!.restart(fullRestart: fullRestart, pause: pause, reason: reason); } - Future stop() => runner.exit(); - Future detach() => runner.detach(); + Future stop() => runner!.exit(); + Future detach() => runner!.detach(); void closeLogger() { _logger.close(); @@ -1289,16 +1299,16 @@ class EmulatorDomain extends Domain { logger: globals.logger, androidSdk: globals.androidSdk, processManager: globals.processManager, - androidWorkflow: androidWorkflow, + androidWorkflow: androidWorkflow!, ); - Future>> getEmulators([ Map args ]) async { + Future>> getEmulators([ Map? args ]) async { final List list = await emulators.getAllAvailableEmulators(); return list.map>(_emulatorToMap).toList(); } Future launch(Map args) async { - final String emulatorId = _getStringArg(args, 'emulatorId', required: true); + final String emulatorId = _getStringArg(args, 'emulatorId', required: true)!; final bool coldBoot = _getBoolArg(args, 'coldBoot') ?? false; final List matches = await emulators.getEmulatorsMatching(emulatorId); @@ -1312,7 +1322,7 @@ class EmulatorDomain extends Domain { } Future> create(Map args) async { - final String name = _getStringArg(args, 'name'); + final String? name = _getStringArg(args, 'name'); final CreateEmulatorResult res = await emulators.createEmulator(name: name); return { 'success': res.success, @@ -1336,16 +1346,16 @@ class ProxyDomain extends Domain { int _id = 0; /// Writes to a file in a local temporary directory. - Future writeTempFile(Map args, Stream> binary) async { - final String path = _getStringArg(args, 'path', required: true); + Future writeTempFile(Map args, Stream>? binary) async { + final String path = _getStringArg(args, 'path', required: true)!; final File file = tempDirectory.childFile(path); await file.parent.create(recursive: true); - await file.openWrite().addStream(binary); + await file.openWrite().addStream(binary!); } /// Calculate rolling hashes for a file in the local temporary directory. - Future> calculateFileHashes(Map args) async { - final String path = _getStringArg(args, 'path', required: true); + Future?> calculateFileHashes(Map args) async { + final String path = _getStringArg(args, 'path', required: true)!; final File file = tempDirectory.childFile(path); if (!await file.exists()) { return null; @@ -1354,24 +1364,24 @@ class ProxyDomain extends Domain { return result.toJson(); } - Future updateFile(Map args, Stream> binary) async { - final String path = _getStringArg(args, 'path', required: true); + Future updateFile(Map args, Stream>? binary) async { + final String path = _getStringArg(args, 'path', required: true)!; final File file = tempDirectory.childFile(path); if (!await file.exists()) { return null; } final List> deltaJson = (args['delta'] as List).cast>(); final List delta = FileDeltaBlock.fromJsonList(deltaJson); - final bool result = await FileTransfer().rebuildFile(file, delta, binary); + final bool result = await FileTransfer().rebuildFile(file, delta, binary!); return result; } /// Opens a connection to a local port, and returns the connection id. Future connect(Map args) async { - final int targetPort = _getIntArg(args, 'port', required: true); + final int targetPort = _getIntArg(args, 'port', required: true)!; final String id = 'portForwarder_${targetPort}_${_id++}'; - Socket socket; + Socket? socket; try { socket = await Socket.connect(InternetAddress.loopbackIPv4, targetPort); @@ -1409,7 +1419,7 @@ class ProxyDomain extends Domain { /// Disconnects from a previously established connection. Future disconnect(Map args) async { - final String id = _getStringArg(args, 'id', required: true); + final String? id = _getStringArg(args, 'id', required: true); if (_forwardedConnections.containsKey(id)) { await _forwardedConnections.remove(id)?.close(); return true; @@ -1418,10 +1428,10 @@ class ProxyDomain extends Domain { } /// Writes to a previously established connection. - Future write(Map args, Stream> binary) async { - final String id = _getStringArg(args, 'id', required: true); + Future write(Map args, Stream>? binary) async { + final String? id = _getStringArg(args, 'id', required: true); if (_forwardedConnections.containsKey(id)) { - final StreamSubscription> subscription = binary.listen(_forwardedConnections[id].add); + final StreamSubscription> subscription = binary!.listen(_forwardedConnections[id!]!.add); await subscription.asFuture(); await subscription.cancel(); return true; @@ -1439,7 +1449,7 @@ class ProxyDomain extends Domain { // to be reused on any subsequent runs. } - Directory _tempDirectory; + Directory? _tempDirectory; Directory get tempDirectory => _tempDirectory ??= globals.fs.systemTempDirectory.childDirectory('flutter_tool_daemon')..createSync(); } @@ -1452,19 +1462,19 @@ class ProxyDomain extends Domain { // TODO(devoncarew): To simplify this code a bit, we could choose to specialize // this class into two, one for each of the above use cases. class AppRunLogger extends DelegatingLogger { - AppRunLogger({ @required Logger parent }) : super(parent); + AppRunLogger({ required Logger parent }) : super(parent); - AppDomain domain; - AppInstance app; + AppDomain? domain; + late AppInstance app; int _nextProgressId = 0; - Status _status; + Status? _status; @override Status startProgress( String message, { - @required Duration timeout, - String progressId, + Duration? timeout, + String? progressId, bool multilineOutput = false, bool includeTiming = true, int progressIndicatorPadding = kDefaultStatusPadding, @@ -1486,7 +1496,7 @@ class AppRunLogger extends DelegatingLogger { finished: true, ); }, stopwatch: Stopwatch())..start(); - return _status; + return _status!; } void close() { @@ -1494,10 +1504,10 @@ class AppRunLogger extends DelegatingLogger { } void _sendProgressEvent({ - @required String eventId, - @required String eventType, + required String eventId, + required String? eventType, bool finished = false, - String message, + String? message, }) { if (domain == null) { // If we're sending progress events before an app has started, send the @@ -1513,16 +1523,16 @@ class AppRunLogger extends DelegatingLogger { if (finished != null) 'finished': finished, }; - domain._sendAppEvent(app, 'progress', event); + domain!._sendAppEvent(app, 'progress', event); } } @override - void sendEvent(String name, [Map args, List binary]) { + void sendEvent(String name, [Map? args, List? binary]) { if (domain == null) { printStatus('event sent after app closed: $name'); } else { - domain.sendEvent(name, args, binary); + domain!.sendEvent(name, args, binary); } } @@ -1542,7 +1552,7 @@ class LogMessage { final String level; final String message; - final StackTrace stackTrace; + final StackTrace? stackTrace; } /// The method by which the Flutter app was launched. @@ -1574,9 +1584,9 @@ enum OperationType { class DebounceOperationQueue { final Map _debounceTimers = {}; final Map> _operationQueue = >{}; - Future _inProgressAction; + Future? _inProgressAction; - Future queueAndDebounce( + Future? queueAndDebounce( K operationType, Duration debounceDuration, Future Function() action, diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index b96db43c0d71..ff1d1a5d4901 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -2,7 +2,7 @@ // 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'; @@ -49,10 +49,10 @@ import 'run.dart'; class DriveCommand extends RunCommandBase { DriveCommand({ bool verboseHelp = false, - @visibleForTesting FlutterDriverFactory flutterDriverFactory, - @required FileSystem fileSystem, - @required Logger logger, - @required Platform platform, + @visibleForTesting FlutterDriverFactory? flutterDriverFactory, + required FileSystem fileSystem, + required Logger? logger, + required Platform platform, }) : _flutterDriverFactory = flutterDriverFactory, _fileSystem = fileSystem, _logger = logger, @@ -156,15 +156,15 @@ class DriveCommand extends RunCommandBase { // specified not to. @override bool get shouldRunPub { - if (argResults.wasParsed('pub') && !boolArgDeprecated('pub')) { + if (argResults!.wasParsed('pub') && !boolArgDeprecated('pub')) { return false; } return true; } - FlutterDriverFactory _flutterDriverFactory; + FlutterDriverFactory? _flutterDriverFactory; final FileSystem _fileSystem; - final Logger _logger; + final Logger? _logger; final FileSystemUtils _fsUtils; @override @@ -179,9 +179,9 @@ class DriveCommand extends RunCommandBase { @override final List aliases = ['driver']; - String get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); + String? get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); - String get screenshot => stringArgDeprecated('screenshot'); + String? get screenshot => stringArgDeprecated('screenshot'); @override bool get startPausedDefault => true; @@ -192,7 +192,7 @@ class DriveCommand extends RunCommandBase { @override Future validateCommand() async { if (userIdentifier != null) { - final Device device = await findTargetDevice(); + final Device? device = await findTargetDevice(); if (device is! AndroidDevice) { throwToolExit('--${FlutterOptions.kDeviceUser} is only supported for Android'); } @@ -202,39 +202,39 @@ class DriveCommand extends RunCommandBase { @override Future runCommand() async { - final String testFile = _getTestFile(); + final String testFile = _getTestFile()!; if (testFile == null) { throwToolExit(null); } if (await _fileSystem.type(testFile) != FileSystemEntityType.file) { throwToolExit('Test file not found: $testFile'); } - final String applicationBinaryPath = stringArgDeprecated(FlutterOptions.kUseApplicationBinary); - final Device device = await findTargetDevice(includeUnsupportedDevices: applicationBinaryPath == null); + final String? applicationBinaryPath = stringArgDeprecated(FlutterOptions.kUseApplicationBinary); + final Device? device = await findTargetDevice(includeUnsupportedDevices: applicationBinaryPath == null); if (device == null) { throwToolExit(null); } if (screenshot != null && !device.supportsScreenshot) { - _logger.printError('Screenshot not supported for ${device.name}.'); + _logger!.printError('Screenshot not supported for ${device.name}.'); } final bool web = device is WebServerDevice || device is ChromiumDevice; _flutterDriverFactory ??= FlutterDriverFactory( - applicationPackageFactory: ApplicationPackageFactory.instance, - logger: _logger, + applicationPackageFactory: ApplicationPackageFactory.instance!, + logger: _logger!, processUtils: globals.processUtils, - dartSdkPath: globals.artifacts.getHostArtifact(HostArtifact.engineDartBinary).path, - devtoolsLauncher: DevtoolsLauncher.instance, + dartSdkPath: globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path, + devtoolsLauncher: DevtoolsLauncher.instance!, ); final PackageConfig packageConfig = await loadPackageConfigWithLogging( _fileSystem.file('.packages'), - logger: _logger, + logger: _logger!, throwOnError: false, - ) ?? PackageConfig.empty; - final DriverService driverService = _flutterDriverFactory.createDriverService(web); + ); + final DriverService driverService = _flutterDriverFactory!.createDriverService(web); final BuildInfo buildInfo = await getBuildInfo(); final DebuggingOptions debuggingOptions = await createDebuggingOptions(web); - final File applicationBinary = applicationBinaryPath == null + final File? applicationBinary = applicationBinaryPath == null ? null : _fileSystem.file(applicationBinaryPath); @@ -245,7 +245,7 @@ class DriveCommand extends RunCommandBase { buildInfo, device, debuggingOptions, - ipv6, + ipv6 ?? false, applicationBinary: applicationBinary, route: route, userIdentifier: userIdentifier, @@ -260,7 +260,7 @@ class DriveCommand extends RunCommandBase { } ); } else { - final Uri uri = Uri.tryParse(stringArgDeprecated('use-existing-app')); + final Uri? uri = Uri.tryParse(stringArgDeprecated('use-existing-app')!); if (uri == null) { throwToolExit('Invalid VM Service URI: ${stringArgDeprecated('use-existing-app')}'); } @@ -268,7 +268,7 @@ class DriveCommand extends RunCommandBase { uri, device, debuggingOptions, - ipv6, + ipv6 ?? false, ); } @@ -279,10 +279,10 @@ class DriveCommand extends RunCommandBase { packageConfig, chromeBinary: stringArgDeprecated('chrome-binary'), headless: boolArgDeprecated('headless'), - browserDimension: stringArgDeprecated('browser-dimension').split(','), + browserDimension: stringArgDeprecated('browser-dimension')!.split(','), browserName: stringArgDeprecated('browser-name'), driverPort: stringArgDeprecated('driver-port') != null - ? int.tryParse(stringArgDeprecated('driver-port')) + ? int.tryParse(stringArgDeprecated('driver-port')!) : null, androidEmulator: boolArgDeprecated('android-emulator'), profileMemory: stringArgDeprecated('profile-memory'), @@ -293,10 +293,10 @@ class DriveCommand extends RunCommandBase { screenshotTaken = true; } - if (boolArgDeprecated('keep-app-running') ?? (argResults['use-existing-app'] != null)) { - _logger.printStatus('Leaving the application running.'); + if (boolArgDeprecated('keep-app-running')) { + _logger!.printStatus('Leaving the application running.'); } else { - final File skslFile = stringArgDeprecated('write-sksl-on-exit') != null + final File? skslFile = stringArgDeprecated('write-sksl-on-exit') != null ? _fileSystem.file(stringArgDeprecated('write-sksl-on-exit')) : null; await driverService.stop(userIdentifier: userIdentifier, writeSkslOnExit: skslFile); @@ -316,8 +316,8 @@ class DriveCommand extends RunCommandBase { return FlutterCommandResult.success(); } - String _getTestFile() { - if (argResults['driver'] != null) { + String? _getTestFile() { + if (argResults!['driver'] != null) { return stringArgDeprecated('driver'); } @@ -332,7 +332,7 @@ class DriveCommand extends RunCommandBase { // for the corresponding test file relative to it. if (!_fileSystem.path.isRelative(appFile)) { if (!_fileSystem.path.isWithin(packageDir, appFile)) { - _logger.printError( + _logger!.printError( 'Application file $appFile is outside the package directory $packageDir' ); return null; @@ -344,7 +344,7 @@ class DriveCommand extends RunCommandBase { final List parts = _fileSystem.path.split(appFile); if (parts.length < 2) { - _logger.printError( + _logger!.printError( 'Application file $appFile must reside in one of the sub-directories ' 'of the package structure, not in the root directory.' ); @@ -372,9 +372,9 @@ class DriveCommand extends RunCommandBase { 'png', ); await device.takeScreenshot(outputFile); - _logger.printStatus('Screenshot written to ${outputFile.path}'); + _logger!.printStatus('Screenshot written to ${outputFile.path}'); } on Exception catch (error) { - _logger.printError('Error taking screenshot: $error'); + _logger!.printError('Error taking screenshot: $error'); } } } diff --git a/packages/flutter_tools/lib/src/commands/precache.dart b/packages/flutter_tools/lib/src/commands/precache.dart index e9f84a3cf950..08632310327d 100644 --- a/packages/flutter_tools/lib/src/commands/precache.dart +++ b/packages/flutter_tools/lib/src/commands/precache.dart @@ -2,10 +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:meta/meta.dart'; - import '../base/common.dart'; import '../base/logger.dart'; import '../base/platform.dart'; @@ -18,10 +14,10 @@ import '../runner/flutter_command.dart'; class PrecacheCommand extends FlutterCommand { PrecacheCommand({ bool verboseHelp = false, - @required Cache cache, - @required Platform platform, - @required Logger logger, - @required FeatureFlags featureFlags, + required Cache? cache, + required Platform platform, + required Logger logger, + required FeatureFlags featureFlags, }) : _cache = cache, _platform = platform, _logger = logger, @@ -30,39 +26,39 @@ class PrecacheCommand extends FlutterCommand { help: 'Precache artifacts for all host platforms.'); argParser.addFlag('force', abbr: 'f', negatable: false, help: 'Force re-downloading of artifacts.'); - argParser.addFlag('android', negatable: true, defaultsTo: false, + argParser.addFlag('android', help: 'Precache artifacts for Android development.', hide: !verboseHelp); - argParser.addFlag('android_gen_snapshot', negatable: true, defaultsTo: false, + argParser.addFlag('android_gen_snapshot', help: 'Precache gen_snapshot for Android development.', hide: !verboseHelp); - argParser.addFlag('android_maven', negatable: true, defaultsTo: false, + argParser.addFlag('android_maven', help: 'Precache Gradle dependencies for Android development.', hide: !verboseHelp); - argParser.addFlag('android_internal_build', negatable: true, defaultsTo: false, + argParser.addFlag('android_internal_build', help: 'Precache dependencies for internal Android development.', hide: !verboseHelp); - argParser.addFlag('ios', negatable: true, defaultsTo: false, + argParser.addFlag('ios', help: 'Precache artifacts for iOS development.'); - argParser.addFlag('web', negatable: true, defaultsTo: false, + argParser.addFlag('web', help: 'Precache artifacts for web development.'); - argParser.addFlag('linux', negatable: true, defaultsTo: false, + argParser.addFlag('linux', help: 'Precache artifacts for Linux desktop development.'); - argParser.addFlag('windows', negatable: true, defaultsTo: false, + argParser.addFlag('windows', help: 'Precache artifacts for Windows desktop development.'); - argParser.addFlag('macos', negatable: true, defaultsTo: false, + argParser.addFlag('macos', help: 'Precache artifacts for macOS desktop development.'); - argParser.addFlag('fuchsia', negatable: true, defaultsTo: false, + argParser.addFlag('fuchsia', help: 'Precache artifacts for Fuchsia development.'); - argParser.addFlag('universal', negatable: true, defaultsTo: true, + argParser.addFlag('universal', defaultsTo: true, help: 'Precache artifacts required for any development platform.'); - argParser.addFlag('flutter_runner', negatable: true, defaultsTo: false, + argParser.addFlag('flutter_runner', help: 'Precache the flutter runner artifacts.', hide: !verboseHelp); - argParser.addFlag('use-unsigned-mac-binaries', negatable: true, defaultsTo: false, + argParser.addFlag('use-unsigned-mac-binaries', help: 'Precache the unsigned macOS binaries when available.', hide: !verboseHelp); } - final Cache _cache; + final Cache? _cache; final Logger _logger; final Platform _platform; final FeatureFlags _featureFlags; @@ -106,9 +102,9 @@ class PrecacheCommand extends FlutterCommand { Set _explicitArtifactSelections() { final Map umbrellaForArtifact = _umbrellaForArtifactMap(); final Set selections = {}; - bool explicitlySelected(String name) => boolArgDeprecated(name) && argResults.wasParsed(name); + bool explicitlySelected(String name) => boolArgDeprecated(name) && argResults!.wasParsed(name); for (final DevelopmentArtifact artifact in DevelopmentArtifact.values) { - final String umbrellaName = umbrellaForArtifact[artifact.name]; + final String? umbrellaName = umbrellaForArtifact[artifact.name]; if (explicitlySelected(artifact.name) || (umbrellaName != null && explicitlySelected(umbrellaName))) { selections.add(artifact.name); @@ -120,11 +116,11 @@ class PrecacheCommand extends FlutterCommand { @override Future validateCommand() { _expandedArtifacts.forEach((String umbrellaName, List childArtifactNames) { - if (!argResults.arguments.contains('--no-$umbrellaName')) { + if (!argResults!.arguments.contains('--no-$umbrellaName')) { return; } for (final String childArtifactName in childArtifactNames) { - if (argResults.arguments.contains('--$childArtifactName')) { + if (argResults!.arguments.contains('--$childArtifactName')) { throwToolExit('--$childArtifactName requires --$umbrellaName'); } } @@ -137,21 +133,21 @@ class PrecacheCommand extends FlutterCommand { Future runCommand() async { // Re-lock the cache. if (_platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') { - await _cache.lock(); + await _cache!.lock(); } if (boolArgDeprecated('force')) { - _cache.clearStampFiles(); + _cache!.clearStampFiles(); } final bool includeAllPlatforms = boolArgDeprecated('all-platforms'); if (includeAllPlatforms) { - _cache.includeAllPlatforms = true; + _cache!.includeAllPlatforms = true; } if (boolArgDeprecated('use-unsigned-mac-binaries')) { - _cache.useUnsignedMacBinaries = true; + _cache!.useUnsignedMacBinaries = true; } final Set explicitlyEnabled = _explicitArtifactSelections(); - _cache.platformOverrideArtifacts = explicitlyEnabled; + _cache!.platformOverrideArtifacts = explicitlyEnabled; // If the user did not provide any artifact flags, then download // all artifacts that correspond to an enabled platform. @@ -159,7 +155,7 @@ class PrecacheCommand extends FlutterCommand { final Map umbrellaForArtifact = _umbrellaForArtifactMap(); final Set requiredArtifacts = {}; for (final DevelopmentArtifact artifact in DevelopmentArtifact.values) { - if (artifact.feature != null && !_featureFlags.isEnabled(artifact.feature)) { + if (artifact.feature != null && !_featureFlags.isEnabled(artifact.feature!)) { continue; } @@ -168,8 +164,8 @@ class PrecacheCommand extends FlutterCommand { requiredArtifacts.add(artifact); } } - if (!await _cache.isUpToDate()) { - await _cache.updateAll(requiredArtifacts); + if (!await _cache!.isUpToDate()) { + await _cache!.updateAll(requiredArtifacts); } else { _logger.printStatus('Already up-to-date.'); } diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index e4ef492c9a8f..d986f7cdb7ae 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart @@ -2,7 +2,7 @@ // 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'; @@ -31,7 +31,7 @@ import 'daemon.dart'; /// Shared logic between `flutter run` and `flutter drive` commands. abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopmentArtifacts { - RunCommandBase({ @required bool verboseHelp }) { + RunCommandBase({ required bool verboseHelp }) { addBuildModeFlags(verboseHelp: verboseHelp, defaultToRelease: false); usesDartDefineOption(); usesFlavorOption(); @@ -182,7 +182,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment bool get purgePersistentCache => boolArgDeprecated('purge-persistent-cache'); bool get disableServiceAuthCodes => boolArgDeprecated('disable-service-auth-codes'); bool get cacheStartupProfile => boolArgDeprecated('cache-startup-profile'); - bool get runningWithPrebuiltApplication => argResults[FlutterOptions.kUseApplicationBinary] != null; + bool get runningWithPrebuiltApplication => argResults![FlutterOptions.kUseApplicationBinary] != null; bool get trackWidgetCreation => boolArgDeprecated('track-widget-creation'); bool get enableImpeller => boolArgDeprecated('enable-impeller'); bool get uninstallFirst => boolArgDeprecated('uninstall-first'); @@ -193,17 +193,17 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment /// Whether to start the application paused by default. bool get startPausedDefault; - String get route => stringArgDeprecated('route'); + String? get route => stringArgDeprecated('route'); - String get traceAllowlist => stringArgDeprecated('trace-allowlist'); + String? get traceAllowlist => stringArgDeprecated('trace-allowlist'); /// Create a debugging options instance for the current `run` or `drive` invocation. @visibleForTesting @protected Future createDebuggingOptions(bool webMode) async { final BuildInfo buildInfo = await getBuildInfo(); - final int browserDebugPort = featureFlags.isWebEnabled && argResults.wasParsed('web-browser-debug-port') - ? int.parse(stringArgDeprecated('web-browser-debug-port')) + final int? browserDebugPort = featureFlags.isWebEnabled && argResults!.wasParsed('web-browser-debug-port') + ? int.parse(stringArgDeprecated('web-browser-debug-port')!) : null; if (buildInfo.mode.isRelease) { return DebuggingOptions.disabled( @@ -293,7 +293,6 @@ class RunCommand extends RunCommandBase { "By default, the widgets library's binding takes care of sending this event.", ) ..addFlag('use-test-fonts', - negatable: true, help: 'Enable (and default to) the "Ahem" font. This is a special font ' 'used in tests to remove any dependencies on the font metrics. It ' 'is enabled when you use "flutter test". Set this flag when running ' @@ -315,12 +314,10 @@ class RunCommand extends RunCommandBase { 'and progress in machine friendly format.', ) ..addFlag('hot', - negatable: true, defaultsTo: kHotReloadDefault, help: 'Run with support for hot reloading. Only available for debug mode. Not available with "--trace-startup".', ) ..addFlag('resident', - negatable: true, defaultsTo: true, hide: !verboseHelp, help: 'Stay resident after launching the application. Not available with "--trace-startup".', @@ -349,8 +346,6 @@ class RunCommand extends RunCommandBase { // is slower for certain use cases. // See: https://github.com/flutter/flutter/issues/49499 ..addFlag('fast-start', - negatable: true, - defaultsTo: false, help: 'Whether to quickly bootstrap applications with a minimal app. ' 'Currently this is only supported on Android devices. This option ' 'cannot be paired with "--${FlutterOptions.kUseApplicationBinary}".', @@ -371,25 +366,25 @@ class RunCommand extends RunCommandBase { @override String get category => FlutterCommandCategory.project; - List devices; + List? devices; bool webMode = false; - String get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); + String? get userIdentifier => stringArgDeprecated(FlutterOptions.kDeviceUser); @override bool get startPausedDefault => false; @override - Future get usagePath async { - final String command = await super.usagePath; + Future get usagePath async { + final String? command = await super.usagePath; if (devices == null) { return command; } - if (devices.length > 1) { + if (devices!.length > 1) { return '$command/all'; } - return '$command/${getNameForTargetPlatform(await devices[0].targetPlatform)}'; + return '$command/${getNameForTargetPlatform(await devices![0].targetPlatform)}'; } @override @@ -399,22 +394,22 @@ class RunCommand extends RunCommandBase { bool anyAndroidDevices = false; bool anyIOSDevices = false; - if (devices == null || devices.isEmpty) { + if (devices == null || devices!.isEmpty) { deviceType = 'none'; deviceOsVersion = 'none'; isEmulator = false; - } else if (devices.length == 1) { - final TargetPlatform platform = await devices[0].targetPlatform; + } else if (devices!.length == 1) { + final TargetPlatform platform = await devices![0].targetPlatform; anyAndroidDevices = platform == TargetPlatform.android; anyIOSDevices = platform == TargetPlatform.ios; deviceType = getNameForTargetPlatform(platform); - deviceOsVersion = await devices[0].sdkNameAndVersion; - isEmulator = await devices[0].isLocalEmulator; + deviceOsVersion = await devices![0].sdkNameAndVersion; + isEmulator = await devices![0].isLocalEmulator; } else { deviceType = 'multiple'; deviceOsVersion = 'multiple'; isEmulator = false; - for (final Device device in devices) { + for (final Device device in devices!) { final TargetPlatform platform = await device.targetPlatform; anyAndroidDevices = anyAndroidDevices || (platform == TargetPlatform.android); anyIOSDevices = anyIOSDevices || (platform == TargetPlatform.ios); @@ -424,7 +419,7 @@ class RunCommand extends RunCommandBase { } } - String androidEmbeddingVersion; + String? androidEmbeddingVersion; final List hostLanguage = []; if (anyAndroidDevices) { final AndroidProject androidProject = FlutterProject.current().android; @@ -469,7 +464,7 @@ class RunCommand extends RunCommandBase { } bool shouldUseHotMode(BuildInfo buildInfo) { - final bool hotArg = boolArgDeprecated('hot') ?? false; + final bool hotArg = boolArgDeprecated('hot'); final bool shouldUseHotMode = hotArg && !traceStartup; return buildInfo.isDebug && shouldUseHotMode; } @@ -489,33 +484,33 @@ class RunCommand extends RunCommandBase { if (devices == null) { throwToolExit(null); } - if (globals.deviceManager.hasSpecifiedAllDevices && runningWithPrebuiltApplication) { + if (globals.deviceManager!.hasSpecifiedAllDevices && runningWithPrebuiltApplication) { throwToolExit('Using "-d all" with "--${FlutterOptions.kUseApplicationBinary}" is not supported'); } if (userIdentifier != null - && devices.every((Device device) => device is! AndroidDevice)) { + && devices!.every((Device device) => device is! AndroidDevice)) { throwToolExit( '--${FlutterOptions.kDeviceUser} is only supported for Android. At least one Android device is required.' ); } - if (devices.any((Device device) => device is AndroidDevice)) { + if (devices!.any((Device device) => device is AndroidDevice)) { _deviceDeprecationBehavior = DeprecationBehavior.exit; } // Only support "web mode" with a single web device due to resident runner // refactoring required otherwise. webMode = featureFlags.isWebEnabled && - devices.length == 1 && - await devices.single.targetPlatform == TargetPlatform.web_javascript; + devices!.length == 1 && + await devices!.single.targetPlatform == TargetPlatform.web_javascript; } @visibleForTesting - Future createRunner({ - @required bool hotMode, - @required List flutterDevices, - @required String applicationBinaryPath, - @required FlutterProject flutterProject, + Future createRunner({ + required bool hotMode, + required List flutterDevices, + required String? applicationBinaryPath, + required FlutterProject flutterProject, }) async { if (hotMode && !webMode) { return HotRunner( @@ -529,11 +524,11 @@ class RunCommand extends RunCommandBase { projectRootPath: stringArgDeprecated('project-root'), dillOutputPath: stringArgDeprecated('output-dill'), stayResident: stayResident, - ipv6: ipv6, + ipv6: ipv6 ?? false, multidexEnabled: boolArgDeprecated('multidex'), ); } else if (webMode) { - return webRunnerFactory.createWebRunner( + return webRunnerFactory!.createWebRunner( flutterDevices.single, target: targetFile, flutterProject: flutterProject, @@ -556,7 +551,7 @@ class RunCommand extends RunCommandBase { applicationBinary: applicationBinaryPath == null ? null : globals.fs.file(applicationBinaryPath), - ipv6: ipv6, + ipv6: ipv6 ?? false, stayResident: stayResident, multidexEnabled: boolArgDeprecated('multidex'), ); @@ -583,33 +578,33 @@ class RunCommand extends RunCommandBase { // debug mode. final BuildInfo buildInfo = await getBuildInfo(); final bool hotMode = shouldUseHotMode(buildInfo); - final String applicationBinaryPath = stringArgDeprecated(FlutterOptions.kUseApplicationBinary); + final String? applicationBinaryPath = stringArgDeprecated(FlutterOptions.kUseApplicationBinary); if (boolArgDeprecated('machine')) { - if (devices.length > 1) { + if (devices!.length > 1) { throwToolExit('"--machine" does not support "-d all".'); } final Daemon daemon = createMachineDaemon(); - AppInstance app; + late AppInstance app; try { app = await daemon.appDomain.startApp( - devices.first, globals.fs.currentDirectory.path, targetFile, route, + devices!.first, globals.fs.currentDirectory.path, targetFile, route, await createDebuggingOptions(webMode), hotMode, applicationBinary: applicationBinaryPath == null ? null : globals.fs.file(applicationBinaryPath), trackWidgetCreation: trackWidgetCreation, projectRootPath: stringArgDeprecated('project-root'), - packagesFilePath: globalResults['packages'] as String, + packagesFilePath: globalResults!['packages'] as String?, dillOutputPath: stringArgDeprecated('output-dill'), - ipv6: ipv6, + ipv6: ipv6 ?? false, multidexEnabled: boolArgDeprecated('multidex'), ); } on Exception catch (error) { throwToolExit(error.toString()); } final DateTime appStartedTime = globals.systemClock.now(); - final int result = await app.runner.waitForAppToFinish(); + final int result = await app.runner!.waitForAppToFinish(); if (result != 0) { throwToolExit(null, exitCode: result); } @@ -622,7 +617,7 @@ class RunCommand extends RunCommandBase { globals.terminal.usesTerminalUi = true; final BuildMode buildMode = getBuildMode(); - for (final Device device in devices) { + for (final Device device in devices!) { if (!await device.supportsRuntimeMode(buildMode)) { throwToolExit( '${sentenceCase(getFriendlyModeName(buildMode))} ' @@ -649,14 +644,14 @@ class RunCommand extends RunCommandBase { } } - List expFlags; + List? expFlags; if (argParser.options.containsKey(FlutterOptions.kEnableExperiment) && stringsArg(FlutterOptions.kEnableExperiment).isNotEmpty) { expFlags = stringsArg(FlutterOptions.kEnableExperiment); } final FlutterProject flutterProject = FlutterProject.current(); final List flutterDevices = [ - for (final Device device in devices) + for (final Device device in devices!) await FlutterDevice.create( device, experimentalFlags: expFlags, @@ -667,21 +662,21 @@ class RunCommand extends RunCommandBase { ), ]; - final ResidentRunner runner = await createRunner( + final ResidentRunner runner = await (createRunner( applicationBinaryPath: applicationBinaryPath, flutterDevices: flutterDevices, flutterProject: flutterProject, hotMode: hotMode, - ); + ) as FutureOr); - DateTime appStartedTime; + DateTime? appStartedTime; // Sync completer so the completing agent attaching to the resident doesn't // need to know about analytics. // // Do not add more operations to the future. final Completer appStartedTimeRecorder = Completer.sync(); - TerminalHandler handler; + TerminalHandler? handler; // This callback can't throw. unawaited(appStartedTimeRecorder.future.then( (_) { @@ -702,7 +697,7 @@ class RunCommand extends RunCommandBase { } )); try { - final int result = await runner.run( + final int? result = await runner.run( appStartedCompleter: appStartedTimeRecorder, enableDevTools: stayResident && boolArgDeprecated(FlutterCommand.kEnableDevTools), route: route, @@ -723,14 +718,14 @@ class RunCommand extends RunCommandBase { } return FlutterCommandResult( ExitStatus.success, - timingLabelParts: [ + timingLabelParts: [ if (hotMode) 'hot' else 'cold', getModeName(getBuildMode()), - if (devices.length == 1) - getNameForTargetPlatform(await devices[0].targetPlatform) + if (devices!.length == 1) + getNameForTargetPlatform(await devices![0].targetPlatform) else 'multiple', - if (devices.length == 1 && await devices[0].isLocalEmulator) + if (devices!.length == 1 && await devices![0].isLocalEmulator) 'emulator' else null, diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index 438a2f2296cb..d4210700241b 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -2,7 +2,7 @@ // 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:math' as math; @@ -95,7 +95,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { help: 'Run only tests that do not have the specified tags. See: https://pub.dev/packages/test#tagging-tests', ) ..addFlag('start-paused', - defaultsTo: false, negatable: false, help: 'Start in a paused mode and wait for a debugger to connect.\n' 'You must specify a single test file to run, explicitly.\n' @@ -103,23 +102,19 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { 'console once the test has started.', ) ..addFlag('run-skipped', - defaultsTo: false, help: 'Run skipped tests instead of skipping them.', ) ..addFlag('disable-service-auth-codes', - defaultsTo: false, negatable: false, hide: !verboseHelp, help: '(deprecated) Allow connections to the VM service without using authentication codes. ' '(Not recommended! This can open your device to remote code execution attacks!)' ) ..addFlag('coverage', - defaultsTo: false, negatable: false, help: 'Whether to collect coverage information.', ) ..addFlag('merge-coverage', - defaultsTo: false, negatable: false, help: 'Whether to merge coverage data with "coverage/lcov.base.info".\n' 'Implies collecting coverage data. (Requires lcov.)', @@ -153,7 +148,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ) ..addFlag('test-assets', defaultsTo: true, - negatable: true, help: 'Whether to build the assets bundle for testing. ' 'This takes additional time before running the tests. ' 'Consider using "--no-test-assets" if assets are not required.', @@ -191,7 +185,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { 'them separately.' ) ..addFlag('enable-vmservice', - defaultsTo: false, hide: !verboseHelp, help: 'Enables the VM service without "--start-paused". This flag is ' 'intended for use with tests that will use "dart:developer" to ' @@ -255,8 +248,8 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { String get category => FlutterCommandCategory.project; @override - Future verifyThenRunCommand(String commandPath) { - _testFiles = argResults.rest.map(globals.fs.path.absolute).toList(); + Future verifyThenRunCommand(String? commandPath) { + _testFiles = argResults!.rest.map(globals.fs.path.absolute).toList(); if (_testFiles.isEmpty) { // We don't scan the entire package, only the test/ subdirectory, so that // files with names like "hit_test.dart" don't get run. @@ -305,8 +298,8 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { final bool buildTestAssets = boolArgDeprecated('test-assets'); final List names = stringsArg('name'); final List plainNames = stringsArg('plain-name'); - final String tags = stringArgDeprecated('tags'); - final String excludeTags = stringArgDeprecated('exclude-tags'); + final String? tags = stringArgDeprecated('tags'); + final String? excludeTags = stringArgDeprecated('exclude-tags'); final BuildInfo buildInfo = await getBuildInfo(forcedBuildMode: BuildMode.debug); if (buildInfo.packageConfig['test_api'] == null) { @@ -320,11 +313,11 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ); } - String testAssetDirectory; + String? testAssetDirectory; if (buildTestAssets) { await _buildTestAsset(); testAssetDirectory = globals.fs.path. - join(flutterProject?.directory?.path ?? '', 'build', 'unit_test_assets'); + join(flutterProject.directory.path, 'build', 'unit_test_assets'); } final bool startPaused = boolArgDeprecated('start-paused'); @@ -335,14 +328,14 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ); } - int jobs = int.tryParse(stringArgDeprecated('concurrency')); + int? jobs = int.tryParse(stringArgDeprecated('concurrency')!); if (jobs == null || jobs <= 0 || !jobs.isFinite) { throwToolExit( 'Could not parse -j/--concurrency argument. It must be an integer greater than zero.' ); } if (_isIntegrationTest) { - if (argResults.wasParsed('concurrency')) { + if (argResults!.wasParsed('concurrency')) { globals.printStatus( '-j/--concurrency was parsed but will be ignored, this option is not ' 'supported when running Integration Tests.', @@ -353,13 +346,13 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { jobs = 1; } - final int shardIndex = int.tryParse(stringArgDeprecated('shard-index') ?? ''); + final int? shardIndex = int.tryParse(stringArgDeprecated('shard-index') ?? ''); if (shardIndex != null && (shardIndex < 0 || !shardIndex.isFinite)) { throwToolExit( 'Could not parse --shard-index=$shardIndex argument. It must be an integer greater than -1.'); } - final int totalShards = int.tryParse(stringArgDeprecated('total-shards') ?? ''); + final int? totalShards = int.tryParse(stringArgDeprecated('total-shards') ?? ''); if (totalShards != null && (totalShards <= 0 || !totalShards.isFinite)) { throwToolExit( 'Could not parse --total-shards=$totalShards argument. It must be an integer greater than zero.'); @@ -375,7 +368,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { } final bool machine = boolArgDeprecated('machine'); - CoverageCollector collector; + CoverageCollector? collector; if (boolArgDeprecated('coverage') || boolArgDeprecated('merge-coverage')) { final String projectName = flutterProject.manifest.appName; collector = CoverageCollector( @@ -385,7 +378,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ); } - TestWatcher watcher; + TestWatcher? watcher; if (machine) { watcher = EventPrinter(parent: collector, out: globals.stdio.stdout); } else if (collector != null) { @@ -402,7 +395,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { nullAssertions: boolArgDeprecated(FlutterOptions.kNullAssertions), ); - Device integrationTestDevice; + Device? integrationTestDevice; if (_isIntegrationTest) { integrationTestDevice = await findTargetDevice(); diff --git a/packages/flutter_tools/lib/src/context_runner.dart b/packages/flutter_tools/lib/src/context_runner.dart index 7dcda5c5e6aa..86689f490dd9 100644 --- a/packages/flutter_tools/lib/src/context_runner.dart +++ b/packages/flutter_tools/lib/src/context_runner.dart @@ -2,7 +2,7 @@ // 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'; @@ -70,12 +70,12 @@ import 'windows/windows_workflow.dart'; Future runInContext( FutureOr Function() runner, { - Map overrides, + Map? overrides, }) async { // Wrap runner with any asynchronous initialization that should run with the // overrides and callbacks. - bool runningOnBot; + late bool runningOnBot; FutureOr runnerWrapper() async { runningOnBot = await globals.isRunningOnBot; return runner(); @@ -90,9 +90,9 @@ Future runInContext( logger: globals.logger, processManager: globals.processManager, fileSystem: globals.fs, - artifacts: globals.artifacts, + artifacts: globals.artifacts!, usage: globals.flutterUsage, - gradleUtils: globals.gradleUtils, + gradleUtils: globals.gradleUtils!, platform: globals.platform, ), AndroidLicenseValidator: () => AndroidLicenseValidator( @@ -158,11 +158,11 @@ Future runInContext( processManager: globals.processManager, logger: globals.logger, platform: globals.platform, - xcodeProjectInterpreter: globals.xcodeProjectInterpreter, + xcodeProjectInterpreter: globals.xcodeProjectInterpreter!, usage: globals.flutterUsage, ), CocoaPodsValidator: () => CocoaPodsValidator( - globals.cocoaPods, + globals.cocoaPods!, globals.userMessages, ), Config: () => Config( @@ -187,29 +187,29 @@ Future runInContext( processManager: globals.processManager, platform: globals.platform, androidSdk: globals.androidSdk, - iosSimulatorUtils: globals.iosSimulatorUtils, + iosSimulatorUtils: globals.iosSimulatorUtils!, featureFlags: featureFlags, fileSystem: globals.fs, - iosWorkflow: globals.iosWorkflow, - artifacts: globals.artifacts, + iosWorkflow: globals.iosWorkflow!, + artifacts: globals.artifacts!, flutterVersion: globals.flutterVersion, - androidWorkflow: androidWorkflow, - fuchsiaWorkflow: fuchsiaWorkflow, - xcDevice: globals.xcdevice, + androidWorkflow: androidWorkflow!, + fuchsiaWorkflow: fuchsiaWorkflow!, + xcDevice: globals.xcdevice!, userMessages: globals.userMessages, - windowsWorkflow: windowsWorkflow, + windowsWorkflow: windowsWorkflow!, macOSWorkflow: MacOSWorkflow( platform: globals.platform, featureFlags: featureFlags, ), - fuchsiaSdk: globals.fuchsiaSdk, + fuchsiaSdk: globals.fuchsiaSdk!, operatingSystemUtils: globals.os, terminal: globals.terminal, customDevicesConfig: globals.customDevicesConfig, ), DevtoolsLauncher: () => DevtoolsServerLauncher( processManager: globals.processManager, - dartExecutable: globals.artifacts.getHostArtifact(HostArtifact.engineDartBinary).path, + dartExecutable: globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path, logger: globals.logger, botDetector: globals.botDetector, ), @@ -220,7 +220,7 @@ Future runInContext( processManager: globals.processManager, logger: globals.logger, fileSystem: globals.fs, - androidWorkflow: androidWorkflow, + androidWorkflow: androidWorkflow!, ), FeatureFlags: () => FlutterFeatureFlags( flutterVersion: globals.flutterVersion, @@ -234,7 +234,7 @@ Future runInContext( FuchsiaWorkflow: () => FuchsiaWorkflow( featureFlags: featureFlags, platform: globals.platform, - fuchsiaArtifacts: globals.fuchsiaArtifacts, + fuchsiaArtifacts: globals.fuchsiaArtifacts!, ), GradleUtils: () => GradleUtils( fileSystem: globals.fs, @@ -247,11 +247,11 @@ Future runInContext( IOSSimulatorUtils: () => IOSSimulatorUtils( logger: globals.logger, processManager: globals.processManager, - xcode: globals.xcode, + xcode: globals.xcode!, ), IOSWorkflow: () => IOSWorkflow( featureFlags: featureFlags, - xcode: globals.xcode, + xcode: globals.xcode!, platform: globals.platform, ), LocalEngineLocator: () => LocalEngineLocator( @@ -259,7 +259,7 @@ Future runInContext( logger: globals.logger, platform: globals.platform, fileSystem: globals.fs, - flutterRoot: Cache.flutterRoot, + flutterRoot: Cache.flutterRoot!, ), Logger: () => globals.platform.isWindows ? WindowsStdoutLogger( @@ -287,7 +287,7 @@ Future runInContext( processManager: globals.processManager, ), OutputPreferences: () => OutputPreferences( - wrapText: globals.stdio.hasTerminal ?? false, + wrapText: globals.stdio.hasTerminal, showColor: globals.platform.stdoutSupportsAnsi, stdio: globals.stdio, ), @@ -318,7 +318,7 @@ Future runInContext( SystemClock: () => const SystemClock(), Usage: () => Usage( runningOnBot: runningOnBot, - firstRunMessenger: FirstRunMessenger(persistentToolState: globals.persistentToolState), + firstRunMessenger: FirstRunMessenger(persistentToolState: globals.persistentToolState!), ), UserMessages: () => UserMessages(), VisualStudioValidator: () => VisualStudioValidator( @@ -343,17 +343,17 @@ Future runInContext( processManager: globals.processManager, platform: globals.platform, fileSystem: globals.fs, - xcodeProjectInterpreter: globals.xcodeProjectInterpreter, + xcodeProjectInterpreter: globals.xcodeProjectInterpreter!, ), XCDevice: () => XCDevice( processManager: globals.processManager, logger: globals.logger, - artifacts: globals.artifacts, + artifacts: globals.artifacts!, cache: globals.cache, platform: globals.platform, - xcode: globals.xcode, + xcode: globals.xcode!, iproxy: IProxy( - iproxyPath: globals.artifacts.getHostArtifact( + iproxyPath: globals.artifacts!.getHostArtifact( HostArtifact.iproxy, ).path, logger: globals.logger, diff --git a/packages/flutter_tools/lib/src/daemon.dart b/packages/flutter_tools/lib/src/daemon.dart index 39c621a412a6..154df4cb6db0 100644 --- a/packages/flutter_tools/lib/src/daemon.dart +++ b/packages/flutter_tools/lib/src/daemon.dart @@ -301,7 +301,7 @@ class DaemonConnection { } /// Sends an error response to the other end of the connection. - void sendErrorResponse(Object id, Object error, StackTrace trace) { + void sendErrorResponse(Object id, Object? error, StackTrace trace) { _daemonStreams.send({ 'id': id, 'error': error, diff --git a/packages/flutter_tools/lib/src/desktop_device.dart b/packages/flutter_tools/lib/src/desktop_device.dart index bfc7bb01bd53..351e204bfaf8 100644 --- a/packages/flutter_tools/lib/src/desktop_device.dart +++ b/packages/flutter_tools/lib/src/desktop_device.dart @@ -44,7 +44,7 @@ abstract class DesktopDevice extends Device { final DesktopLogReader _deviceLogReader = DesktopLogReader(); @override - DevFSWriter createDevFSWriter(covariant ApplicationPackage app, String userIdentifier) { + DevFSWriter createDevFSWriter(covariant ApplicationPackage? app, String? userIdentifier) { return LocalDevFSWriter(fileSystem: _fileSystem); } diff --git a/packages/flutter_tools/lib/src/devfs.dart b/packages/flutter_tools/lib/src/devfs.dart index b80be32bedf0..5664bc115302 100644 --- a/packages/flutter_tools/lib/src/devfs.dart +++ b/packages/flutter_tools/lib/src/devfs.dart @@ -477,7 +477,7 @@ class DevFS { final StopwatchFactory _stopwatchFactory; final String fsName; - final Directory rootDirectory; + final Directory? rootDirectory; final Set assetPathsToEvict = {}; // A flag to indicate whether we have called `setAssetDirectory` on the target device. @@ -497,7 +497,7 @@ class DevFS { final String baseUriString = baseUri.toString(); if (deviceUriString.startsWith(baseUriString)) { final String deviceUriSuffix = deviceUriString.substring(baseUriString.length); - return rootDirectory.uri.resolve(deviceUriSuffix); + return rootDirectory!.uri.resolve(deviceUriSuffix); } return deviceUri; } diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 845c1d32da9f..4fbcc64bb5ad 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -557,8 +557,8 @@ abstract class Device { /// For example, the desktop device classes can use a writer which /// copies the files across the local file system. DevFSWriter? createDevFSWriter( - covariant ApplicationPackage app, - String userIdentifier, + covariant ApplicationPackage? app, + String? userIdentifier, ) { return null; } @@ -593,7 +593,7 @@ abstract class Device { /// [platformArgs] allows callers to pass platform-specific arguments to the /// start call. The build mode is not used by all platforms. Future startApp( - covariant ApplicationPackage package, { + covariant ApplicationPackage? package, { String? mainPath, String? route, required DebuggingOptions debuggingOptions, @@ -624,7 +624,7 @@ abstract class Device { /// /// Specify [userIdentifier] to stop app installed to a profile (Android only). Future stopApp( - covariant ApplicationPackage app, { + covariant ApplicationPackage? app, { String? userIdentifier, }); diff --git a/packages/flutter_tools/lib/src/devtools_launcher.dart b/packages/flutter_tools/lib/src/devtools_launcher.dart index c7dfa0c46ac5..c895712d1cd3 100644 --- a/packages/flutter_tools/lib/src/devtools_launcher.dart +++ b/packages/flutter_tools/lib/src/devtools_launcher.dart @@ -2,7 +2,7 @@ // 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'; @@ -20,10 +20,10 @@ import 'resident_runner.dart'; /// start a server instance. class DevtoolsServerLauncher extends DevtoolsLauncher { DevtoolsServerLauncher({ - @required ProcessManager processManager, - @required String dartExecutable, - @required Logger logger, - @required BotDetector botDetector, + required ProcessManager processManager, + required String dartExecutable, + required Logger? logger, + required BotDetector botDetector, }) : _processManager = processManager, _dartExecutable = dartExecutable, _logger = logger, @@ -31,14 +31,14 @@ class DevtoolsServerLauncher extends DevtoolsLauncher { final ProcessManager _processManager; final String _dartExecutable; - final Logger _logger; + final Logger? _logger; final BotDetector _botDetector; final Completer _processStartCompleter = Completer(); - io.Process _devToolsProcess; + io.Process? _devToolsProcess; bool _devToolsProcessKilled = false; @visibleForTesting - Future devToolsProcessExit; + Future? devToolsProcessExit; static final RegExp _serveDevToolsPattern = RegExp(r'Serving DevTools at ((http|//)[a-zA-Z0-9:/=_\-\.\[\]]+?)\.?$'); @@ -47,7 +47,7 @@ class DevtoolsServerLauncher extends DevtoolsLauncher { Future get processStart => _processStartCompleter.future; @override - Future launch(Uri vmServiceUri, {List additionalArguments}) async { + Future launch(Uri? vmServiceUri, {List? additionalArguments}) async { // Place this entire method in a try/catch that swallows exceptions because // this method is guaranteed not to return a Future that throws. try { @@ -60,23 +60,23 @@ class DevtoolsServerLauncher extends DevtoolsLauncher { ]); _processStartCompleter.complete(); final Completer completer = Completer(); - _devToolsProcess.stdout + _devToolsProcess!.stdout .transform(utf8.decoder) .transform(const LineSplitter()) .listen((String line) { - final Match match = _serveDevToolsPattern.firstMatch(line); + final Match? match = _serveDevToolsPattern.firstMatch(line); if (match != null) { - final String url = match[1]; + final String url = match[1]!; completer.complete(Uri.parse(url)); } }); - _devToolsProcess.stderr + _devToolsProcess!.stderr .transform(utf8.decoder) .transform(const LineSplitter()) - .listen(_logger.printError); + .listen(_logger!.printError); final bool runningOnBot = await _botDetector.isRunningOnBot; - devToolsProcessExit = _devToolsProcess.exitCode.then( + devToolsProcessExit = _devToolsProcess!.exitCode.then( (int exitCode) { if (!_devToolsProcessKilled && runningOnBot) { throwToolExit('DevTools process failed: exitCode=$exitCode'); @@ -86,12 +86,12 @@ class DevtoolsServerLauncher extends DevtoolsLauncher { devToolsUrl = await completer.future; } on Exception catch (e, st) { - _logger.printError('Failed to launch DevTools: $e', stackTrace: st); + _logger!.printError('Failed to launch DevTools: $e', stackTrace: st); } } @override - Future serve() async { + Future serve() async { if (activeDevToolsServer == null) { await launch(null); } @@ -105,7 +105,7 @@ class DevtoolsServerLauncher extends DevtoolsLauncher { } if (_devToolsProcess != null) { _devToolsProcessKilled = true; - _devToolsProcess.kill(); + _devToolsProcess!.kill(); } } } diff --git a/packages/flutter_tools/lib/src/drive/drive_service.dart b/packages/flutter_tools/lib/src/drive/drive_service.dart index d1aa1b4b9f57..756c6ecc7b20 100644 --- a/packages/flutter_tools/lib/src/drive/drive_service.dart +++ b/packages/flutter_tools/lib/src/drive/drive_service.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 'package:dds/dds.dart' as dds; @@ -25,11 +23,11 @@ import 'web_driver_service.dart'; class FlutterDriverFactory { FlutterDriverFactory({ - @required ApplicationPackageFactory applicationPackageFactory, - @required Logger logger, - @required ProcessUtils processUtils, - @required String dartSdkPath, - @required DevtoolsLauncher devtoolsLauncher, + required ApplicationPackageFactory applicationPackageFactory, + required Logger logger, + required ProcessUtils processUtils, + required String dartSdkPath, + required DevtoolsLauncher devtoolsLauncher, }) : _applicationPackageFactory = applicationPackageFactory, _logger = logger, _processUtils = processUtils, @@ -69,10 +67,10 @@ abstract class DriverService { Device device, DebuggingOptions debuggingOptions, bool ipv6, { - File applicationBinary, - String route, - String userIdentifier, - String mainPath, + File? applicationBinary, + String? route, + String? userIdentifier, + String? mainPath, Map platformArgs = const {}, }); @@ -94,13 +92,13 @@ abstract class DriverService { List arguments, Map environment, PackageConfig packageConfig, { - bool headless, - String chromeBinary, - String browserName, - bool androidEmulator, - int driverPort, - List browserDimension, - String profileMemory, + bool? headless, + String? chromeBinary, + String? browserName, + bool? androidEmulator, + int? driverPort, + List? browserDimension, + String? profileMemory, }); /// Stop the running application and uninstall it from the device. @@ -109,8 +107,8 @@ abstract class DriverService { /// and write SkSL to the file. This is only supported on mobile and /// desktop devices. Future stop({ - File writeSkslOnExit, - String userIdentifier, + File? writeSkslOnExit, + String? userIdentifier, }); } @@ -118,11 +116,11 @@ abstract class DriverService { /// applications. class FlutterDriverService extends DriverService { FlutterDriverService({ - @required ApplicationPackageFactory applicationPackageFactory, - @required Logger logger, - @required ProcessUtils processUtils, - @required String dartSdkPath, - @required DevtoolsLauncher devtoolsLauncher, + required ApplicationPackageFactory applicationPackageFactory, + required Logger logger, + required ProcessUtils processUtils, + required String dartSdkPath, + required DevtoolsLauncher devtoolsLauncher, @visibleForTesting VMServiceConnector vmServiceConnector = connectToVmService, }) : _applicationPackageFactory = applicationPackageFactory, _logger = logger, @@ -140,10 +138,10 @@ class FlutterDriverService extends DriverService { final VMServiceConnector _vmServiceConnector; final DevtoolsLauncher _devtoolsLauncher; - Device _device; - ApplicationPackage _applicationPackage; - String _vmServiceUri; - FlutterVmService _vmService; + Device? _device; + ApplicationPackage? _applicationPackage; + late String _vmServiceUri; + late FlutterVmService _vmService; @override Future start( @@ -151,11 +149,11 @@ class FlutterDriverService extends DriverService { Device device, DebuggingOptions debuggingOptions, bool ipv6, { - File applicationBinary, - String route, - String userIdentifier, + File? applicationBinary, + String? route, + String? userIdentifier, Map platformArgs = const {}, - String mainPath, + String? mainPath, }) async { if (buildInfo.isRelease) { throwToolExit( @@ -173,7 +171,7 @@ class FlutterDriverService extends DriverService { applicationBinary: applicationBinary, ); int attempt = 0; - LaunchResult result; + LaunchResult? result; bool prebuiltApplication = applicationBinary != null; while (attempt < _kLaunchAttempts) { result = await device.startApp( @@ -197,7 +195,7 @@ class FlutterDriverService extends DriverService { throwToolExit('Application failed to start. Will not run test. Quitting.', exitCode: 1); } return reuseApplication( - result.observatoryUri, + result.observatoryUri!, device, debuggingOptions, ipv6, @@ -251,13 +249,13 @@ class FlutterDriverService extends DriverService { List arguments, Map environment, PackageConfig packageConfig, { - bool headless, - String chromeBinary, - String browserName, - bool androidEmulator, - int driverPort, - List browserDimension, - String profileMemory, + bool? headless, + String? chromeBinary, + String? browserName, + bool? androidEmulator, + int? driverPort, + List? browserDimension, + String? profileMemory, }) async { if (profileMemory != null) { unawaited(_devtoolsLauncher.launch( @@ -285,35 +283,35 @@ class FlutterDriverService extends DriverService { @override Future stop({ - File writeSkslOnExit, - String userIdentifier, + File? writeSkslOnExit, + String? userIdentifier, }) async { if (writeSkslOnExit != null) { final FlutterView flutterView = (await _vmService.getFlutterViews()).first; - final Map result = await _vmService.getSkSLs( + final Map result = await (_vmService.getSkSLs( viewId: flutterView.id - ); - await sharedSkSlWriter(_device, result, outputFile: writeSkslOnExit, logger: _logger); + ) as FutureOr>); + await sharedSkSlWriter(_device!, result, outputFile: writeSkslOnExit, logger: _logger); } // If the application package is available, stop and uninstall. if (_applicationPackage != null) { - if (!await _device.stopApp(_applicationPackage, userIdentifier: userIdentifier)) { + if (!await _device!.stopApp(_applicationPackage, userIdentifier: userIdentifier)) { _logger.printError('Failed to stop app'); } - if (!await _device.uninstallApp(_applicationPackage, userIdentifier: userIdentifier)) { + if (!await _device!.uninstallApp(_applicationPackage!, userIdentifier: userIdentifier)) { _logger.printError('Failed to uninstall app'); } - } else if (_device.supportsFlutterExit) { + } else if (_device!.supportsFlutterExit) { // Otherwise use the VM Service URI to stop the app as a best effort approach. final vm_service.VM vm = await _vmService.service.getVM(); - final vm_service.IsolateRef isolateRef = vm.isolates + final vm_service.IsolateRef isolateRef = vm.isolates! .firstWhere((vm_service.IsolateRef element) { - return !element.isSystemIsolate; - }, orElse: () => null); - unawaited(_vmService.flutterExit(isolateId: isolateRef.id)); + return !element.isSystemIsolate!; + }); + unawaited(_vmService.flutterExit(isolateId: isolateRef.id!)); } else { _logger.printTrace('No application package for $_device, leaving app running'); } - await _device.dispose(); + await _device!.dispose(); } } diff --git a/packages/flutter_tools/lib/src/drive/web_driver_service.dart b/packages/flutter_tools/lib/src/drive/web_driver_service.dart index 8f99f96763fd..e686a08ffb03 100644 --- a/packages/flutter_tools/lib/src/drive/web_driver_service.dart +++ b/packages/flutter_tools/lib/src/drive/web_driver_service.dart @@ -2,7 +2,7 @@ // 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 'dart:math' as math; @@ -28,9 +28,9 @@ import 'drive_service.dart'; /// An implementation of the driver service for web debug and release applications. class WebDriverService extends DriverService { WebDriverService({ - @required ProcessUtils processUtils, - @required String dartSdkPath, - @required Logger logger, + required ProcessUtils processUtils, + required String dartSdkPath, + required Logger logger, }) : _processUtils = processUtils, _dartSdkPath = dartSdkPath, _logger = logger; @@ -39,15 +39,15 @@ class WebDriverService extends DriverService { final String _dartSdkPath; final Logger _logger; - ResidentRunner _residentRunner; - Uri _webUri; + late ResidentRunner _residentRunner; + Uri? _webUri; /// The result of [ResidentRunner.run]. /// /// This is expected to stay `null` throughout the test, as the application /// must be running until [stop] is called. If it becomes non-null, it likely /// indicates a bug. - int _runResult; + int? _runResult; @override Future start( @@ -55,10 +55,10 @@ class WebDriverService extends DriverService { Device device, DebuggingOptions debuggingOptions, bool ipv6, { - File applicationBinary, - String route, - String userIdentifier, - String mainPath, + File? applicationBinary, + String? route, + String? userIdentifier, + String? mainPath, Map platformArgs = const {}, }) async { final FlutterDevice flutterDevice = await FlutterDevice.create( @@ -67,7 +67,7 @@ class WebDriverService extends DriverService { buildInfo: buildInfo, platform: globals.platform, ); - _residentRunner = webRunnerFactory.createWebRunner( + _residentRunner = webRunnerFactory!.createWebRunner( flutterDevice, target: mainPath, ipv6: ipv6, @@ -90,21 +90,21 @@ class WebDriverService extends DriverService { systemClock: globals.systemClock, ); final Completer appStartedCompleter = Completer.sync(); - final Future runFuture = _residentRunner.run( + final Future runFuture = _residentRunner.run( appStartedCompleter: appStartedCompleter, route: route, ); bool isAppStarted = false; await Future.any(>[ - runFuture.then((int result) { + runFuture.then((int? result) { _runResult = result; return null; - }), + } as FutureOr Function(int?)), appStartedCompleter.future.then((_) { isAppStarted = true; return null; - }), + } as FutureOr Function(void)), ]); if (_runResult != null) { @@ -126,22 +126,25 @@ class WebDriverService extends DriverService { } @override - Future startTest(String testFile, List arguments, Map environment, PackageConfig packageConfig, { - @required bool headless, - String chromeBinary, - @required String browserName, - bool androidEmulator, - int driverPort, - List browserDimension, - String profileMemory, + Future startTest( + String testFile, + List arguments, + Map environment, + PackageConfig packageConfig, { + bool? headless, + String? chromeBinary, + String? browserName, + bool? androidEmulator, + int? driverPort, + List? browserDimension, + String? profileMemory, }) async { - async_io.WebDriver webDriver; + late async_io.WebDriver webDriver; final Browser browser = _browserNameToEnum(browserName); try { webDriver = await async_io.createDriver( uri: Uri.parse('http://localhost:$driverPort/'), desired: getDesiredCapabilities(browser, headless, chromeBinary), - spec: async_io.WebDriverSpec.Auto ); } on SocketException catch (error) { _logger.printTrace('$error'); @@ -156,11 +159,11 @@ class WebDriverService extends DriverService { final bool isAndroidChrome = browser == Browser.androidChrome; // Do not set the window size for android chrome browser. if (!isAndroidChrome) { - assert(browserDimension.length == 2); - int x; - int y; + assert(browserDimension!.length == 2); + late int x; + late int y; try { - x = int.parse(browserDimension[0]); + x = int.parse(browserDimension![0]); y = int.parse(browserDimension[1]); } on FormatException catch (ex) { throwToolExit('Dimension provided to --browser-dimension is invalid: $ex'); @@ -184,7 +187,7 @@ class WebDriverService extends DriverService { } @override - Future stop({File writeSkslOnExit, String userIdentifier}) async { + Future stop({File? writeSkslOnExit, String? userIdentifier}) async { final bool appDidFinishPrematurely = _runResult != null; await _residentRunner.exitApp(); await _residentRunner.cleanupAtFinish(); @@ -197,7 +200,7 @@ class WebDriverService extends DriverService { } } - Map _additionalDriverEnvironment(async_io.WebDriver webDriver, String browserName, bool androidEmulator) { + Map _additionalDriverEnvironment(async_io.WebDriver webDriver, String? browserName, bool? androidEmulator) { return { 'DRIVER_SESSION_ID': webDriver.id, 'DRIVER_SESSION_URI': webDriver.uri.toString(), @@ -205,7 +208,7 @@ class WebDriverService extends DriverService { 'DRIVER_SESSION_CAPABILITIES': json.encode(webDriver.capabilities), 'SUPPORT_TIMELINE_ACTION': (_browserNameToEnum(browserName) == Browser.chrome).toString(), 'FLUTTER_WEB_TEST': 'true', - 'ANDROID_CHROME_ON_EMULATOR': (_browserNameToEnum(browserName) == Browser.androidChrome && androidEmulator).toString(), + 'ANDROID_CHROME_ON_EMULATOR': (_browserNameToEnum(browserName) == Browser.androidChrome && androidEmulator!).toString(), }; } @@ -234,7 +237,7 @@ enum Browser { /// Returns desired capabilities for given [browser], [headless] and /// [chromeBinary]. @visibleForTesting -Map getDesiredCapabilities(Browser browser, bool headless, [String chromeBinary]) { +Map getDesiredCapabilities(Browser browser, bool? headless, [String? chromeBinary]) { switch (browser) { case Browser.chrome: return { @@ -258,7 +261,7 @@ Map getDesiredCapabilities(Browser browser, bool headless, [Str '--no-default-browser-check', '--no-sandbox', '--no-first-run', - if (headless) '--headless', + if (headless!) '--headless', ], 'perfLoggingPrefs': { 'traceCategories': @@ -268,14 +271,13 @@ Map getDesiredCapabilities(Browser browser, bool headless, [Str }, }, }; - break; case Browser.firefox: return { 'acceptInsecureCerts': true, 'browserName': 'firefox', 'moz:firefoxOptions' : { 'args': [ - if (headless) '-headless', + if (headless!) '-headless', ], 'prefs': { 'dom.file.createInChild': true, @@ -290,18 +292,15 @@ Map getDesiredCapabilities(Browser browser, bool headless, [Str 'log': {'level': 'trace'}, }, }; - break; case Browser.edge: return { 'acceptInsecureCerts': true, 'browserName': 'edge', }; - break; case Browser.safari: return { 'browserName': 'safari', }; - break; case Browser.iosSafari: return { 'platformName': 'ios', @@ -318,11 +317,10 @@ Map getDesiredCapabilities(Browser browser, bool headless, [Str }, }; } - throw UnsupportedError('Browser $browser not supported.'); // dead code; remove with null safety migration } /// Converts [browserName] string to [Browser] -Browser _browserNameToEnum(String browserName) { +Browser _browserNameToEnum(String? browserName) { switch (browserName) { case 'android-chrome': return Browser.androidChrome; case 'chrome': return Browser.chrome; diff --git a/packages/flutter_tools/lib/src/flutter_application_package.dart b/packages/flutter_tools/lib/src/flutter_application_package.dart index c7afa223d372..f1a8cba283f7 100644 --- a/packages/flutter_tools/lib/src/flutter_application_package.dart +++ b/packages/flutter_tools/lib/src/flutter_application_package.dart @@ -25,7 +25,7 @@ import 'windows/application_package.dart'; /// A package factory that supports all Flutter target platforms. class FlutterApplicationPackageFactory extends ApplicationPackageFactory { FlutterApplicationPackageFactory({ - required AndroidSdk androidSdk, + required AndroidSdk? androidSdk, required ProcessManager processManager, required Logger logger, required UserMessages userMessages, @@ -38,7 +38,7 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory { _processUtils = ProcessUtils(logger: logger, processManager: processManager); - final AndroidSdk _androidSdk; + final AndroidSdk? _androidSdk; final ProcessManager _processManager; final Logger _logger; final ProcessUtils _processUtils; @@ -72,7 +72,7 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory { applicationBinary, processManager: _processManager, logger: _logger, - androidSdk: _androidSdk, + androidSdk: _androidSdk!, userMessages: _userMessages, processUtils: _processUtils, ); diff --git a/packages/flutter_tools/lib/src/flutter_device_manager.dart b/packages/flutter_tools/lib/src/flutter_device_manager.dart index 887783b5df42..f30a0da5c83a 100644 --- a/packages/flutter_tools/lib/src/flutter_device_manager.dart +++ b/packages/flutter_tools/lib/src/flutter_device_manager.dart @@ -40,7 +40,7 @@ class FlutterDeviceManager extends DeviceManager { required Platform platform, required ProcessManager processManager, required FileSystem fileSystem, - required AndroidSdk androidSdk, + required AndroidSdk? androidSdk, required FeatureFlags featureFlags, required IOSSimulatorUtils iosSimulatorUtils, required XCDevice xcDevice, diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index ea8d1fc7afe9..5484510022ce 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -338,7 +338,7 @@ class IOSSimulator extends Device { final SimControl _simControl; @override - DevFSWriter createDevFSWriter(covariant ApplicationPackage app, String userIdentifier) { + DevFSWriter createDevFSWriter(covariant ApplicationPackage? app, String? userIdentifier) { return LocalDevFSWriter(fileSystem: globals.fs); } diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index f228b7ff8df4..eb38d2e5f3c5 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -2,12 +2,11 @@ // 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 'dart:typed_data'; import 'package:dwds/data/build_result.dart'; +// ignore: import_of_legacy_library_into_null_safe import 'package:dwds/dwds.dart'; import 'package:html/dom.dart'; import 'package:html/parser.dart'; @@ -46,24 +45,24 @@ import '../web/memory_fs.dart'; import 'sdk_web_configuration.dart'; typedef DwdsLauncher = Future Function({ - @required AssetReader assetReader, - @required Stream buildResults, - @required ConnectionProvider chromeConnection, - @required LoadStrategy loadStrategy, - @required bool enableDebugging, - ExpressionCompiler expressionCompiler, - bool enableDebugExtension, - String hostname, - bool useSseForDebugProxy, - bool useSseForDebugBackend, - bool useSseForInjectedClient, - UrlEncoder urlEncoder, - bool spawnDds, - bool enableDevtoolsLaunch, - DevtoolsLauncher devtoolsLauncher, - bool launchDevToolsInNewWindow, - SdkConfigurationProvider sdkConfigurationProvider, - bool emitDebugEvents, + required AssetReader assetReader, + required Stream buildResults, + required ConnectionProvider chromeConnection, + required LoadStrategy loadStrategy, + required bool enableDebugging, + ExpressionCompiler? expressionCompiler, + bool? enableDebugExtension, + String? hostname, + bool? useSseForDebugProxy, + bool? useSseForDebugBackend, + bool? useSseForInjectedClient, + UrlEncoder? urlEncoder, + bool? spawnDds, + bool? enableDevtoolsLaunch, + DevtoolsLauncher? devtoolsLauncher, + bool? launchDevToolsInNewWindow, + SdkConfigurationProvider? sdkConfigurationProvider, + bool? emitDebugEvents, }); // A minimal index for projects that do not yet support web. @@ -83,11 +82,11 @@ const String _kDefaultIndex = ''' /// This is only used in development mode. class WebExpressionCompiler implements ExpressionCompiler { WebExpressionCompiler(this._generator, { - @required FileSystem fileSystem, + required FileSystem? fileSystem, }) : _fileSystem = fileSystem; final ResidentCompiler _generator; - final FileSystem _fileSystem; + final FileSystem? _fileSystem; @override Future compileExpressionToJs( @@ -100,13 +99,13 @@ class WebExpressionCompiler implements ExpressionCompiler { String moduleName, String expression, ) async { - final CompilerOutput compilerOutput = + final CompilerOutput? compilerOutput = await _generator.compileExpressionToJs(libraryUri, line, column, jsModules, jsFrameValues, moduleName, expression); if (compilerOutput != null && compilerOutput.outputFilename != null) { final String content = utf8.decode( - _fileSystem.file(compilerOutput.outputFilename).readAsBytesSync()); + _fileSystem!.file(compilerOutput.outputFilename).readAsBytesSync()); return ExpressionCompilationResult( content, compilerOutput.errorCount > 0); } @@ -117,7 +116,7 @@ class WebExpressionCompiler implements ExpressionCompiler { } @override - Future initialize({String moduleFormat, bool soundNullSafety}) async {} + Future initialize({String? moduleFormat, bool? soundNullSafety}) async {} @override Future updateDependencies(Map modules) async => true; @@ -180,10 +179,10 @@ class WebAssetServer implements AssetReader { /// Unhandled exceptions will throw a [ToolExit] with the error and stack /// trace. static Future start( - ChromiumLauncher chromiumLauncher, + ChromiumLauncher? chromiumLauncher, String hostname, - int port, - UrlTunneller urlTunneller, + int? port, + UrlTunneller? urlTunneller, bool useSseForDebugProxy, bool useSseForDebugBackend, bool useSseForInjectedClient, @@ -191,7 +190,7 @@ class WebAssetServer implements AssetReader { bool enableDwds, bool enableDds, Uri entrypoint, - ExpressionCompiler expressionCompiler, + ExpressionCompiler? expressionCompiler, NullSafetyMode nullSafetyMode, { bool testMode = false, DwdsLauncher dwdsLauncher = Dwds.start, @@ -202,7 +201,7 @@ class WebAssetServer implements AssetReader { } else { address = (await InternetAddress.lookup(hostname)).first; } - HttpServer httpServer; + HttpServer? httpServer; const int kMaxRetries = 4; for (int i = 0; i <= kMaxRetries; i++) { try { @@ -218,7 +217,7 @@ class WebAssetServer implements AssetReader { } // Allow rendering in a iframe. - httpServer.defaultResponseHeaders.remove('x-frame-options', 'SAMEORIGIN'); + httpServer!.defaultResponseHeaders.remove('x-frame-options', 'SAMEORIGIN'); final PackageConfig packageConfig = buildInfo.packageConfig; final Map digests = {}; @@ -246,7 +245,7 @@ class WebAssetServer implements AssetReader { basePath: server.basePath, ); runZonedGuarded(() { - shelf.serveRequests(httpServer, releaseAssetServer.handle); + shelf.serveRequests(httpServer!, releaseAssetServer.handle); }, (Object e, StackTrace s) { globals.printTrace('Release asset server: error serving requests: $e:$s'); }); @@ -284,7 +283,7 @@ class WebAssetServer implements AssetReader { enableDebugExtension: true, buildResults: const Stream.empty(), chromeConnection: () async { - final Chromium chromium = await chromiumLauncher.connectedInstance; + final Chromium chromium = await chromiumLauncher!.connectedInstance; return chromium.chromeConnection; }, hostname: hostname, @@ -297,11 +296,11 @@ class WebAssetServer implements AssetReader { ReloadConfiguration.none, server, digestProvider, - server.basePath, + server.basePath!, ).strategy, expressionCompiler: expressionCompiler, spawnDds: enableDds, - sdkConfigurationProvider: SdkWebConfigurationProvider(globals.artifacts), + sdkConfigurationProvider: SdkWebConfigurationProvider(globals.artifacts!), ); shelf.Pipeline pipeline = const shelf.Pipeline(); if (enableDwds) { @@ -313,42 +312,42 @@ class WebAssetServer implements AssetReader { final shelf.Cascade cascade = shelf.Cascade().add(dwds.handler).add(dwdsHandler); runZonedGuarded(() { - shelf.serveRequests(httpServer, cascade.handler); + shelf.serveRequests(httpServer!, cascade.handler); }, (Object e, StackTrace s) { globals.printTrace('Dwds server: error serving requests: $e:$s'); }); server.dwds = dwds; + server._dwdsInit = true; return server; } final NullSafetyMode _nullSafetyMode; final HttpServer _httpServer; final WebMemoryFS _webMemoryFS = WebMemoryFS(); - - final PackageConfig _packages; final InternetAddress internetAddress; - /* late final */ Dwds dwds; - Directory entrypointCacheDirectory; + late final Dwds dwds; + late Directory entrypointCacheDirectory; + bool _dwdsInit = false; @visibleForTesting HttpHeaders get defaultResponseHeaders => _httpServer.defaultResponseHeaders; @visibleForTesting - Uint8List getFile(String path) => _webMemoryFS.files[path]; + Uint8List? getFile(String path) => _webMemoryFS.files[path]; @visibleForTesting - Uint8List getSourceMap(String path) => _webMemoryFS.sourcemaps[path]; + Uint8List? getSourceMap(String path) => _webMemoryFS.sourcemaps[path]; @visibleForTesting - Uint8List getMetadata(String path) => _webMemoryFS.metadataFiles[path]; + Uint8List? getMetadata(String path) => _webMemoryFS.metadataFiles[path]; @visibleForTesting /// The base path to serve from. /// /// It should have no leading or trailing slashes. - String basePath = ''; + String? basePath = ''; // handle requests for JavaScript source, dart sources maps, or asset files. @visibleForTesting @@ -358,7 +357,7 @@ class WebAssetServer implements AssetReader { return shelf.Response.notFound(''); } - final String requestPath = _stripBasePath(request.url.path, basePath); + final String? requestPath = _stripBasePath(request.url.path, basePath); if (requestPath == null) { return shelf.Response.notFound(''); @@ -372,7 +371,7 @@ class WebAssetServer implements AssetReader { final Map headers = {}; // Track etag headers for better caching of resources. - final String ifNoneMatch = request.headers[HttpHeaders.ifNoneMatchHeader]; + final String? ifNoneMatch = request.headers[HttpHeaders.ifNoneMatchHeader]; headers[HttpHeaders.cacheControlHeader] = 'max-age=0, must-revalidate'; // If this is a JavaScript file, it must be in the in-memory cache. @@ -380,7 +379,7 @@ class WebAssetServer implements AssetReader { final String webServerPath = requestPath.replaceFirst('.dart.js', '.dart.lib.js'); if (_webMemoryFS.files.containsKey(requestPath) || _webMemoryFS.files.containsKey(webServerPath)) { - final List bytes = getFile(requestPath) ?? getFile(webServerPath); + final List? bytes = getFile(requestPath) ?? getFile(webServerPath); // Use the underlying buffer hashCode as a revision string. This buffer is // replaced whenever the frontend_server produces new output files, which // will also change the hashCode. @@ -388,7 +387,7 @@ class WebAssetServer implements AssetReader { if (ifNoneMatch == etag) { return shelf.Response.notModified(); } - headers[HttpHeaders.contentLengthHeader] = bytes.length.toString(); + headers[HttpHeaders.contentLengthHeader] = bytes!.length.toString(); headers[HttpHeaders.contentTypeHeader] = 'application/javascript'; headers[HttpHeaders.etagHeader] = etag; return shelf.Response.ok(bytes, headers: headers); @@ -396,12 +395,12 @@ class WebAssetServer implements AssetReader { // If this is a sourcemap file, then it might be in the in-memory cache. // Attempt to lookup the file by URI. if (_webMemoryFS.sourcemaps.containsKey(requestPath)) { - final List bytes = getSourceMap(requestPath); + final List? bytes = getSourceMap(requestPath); final String etag = bytes.hashCode.toString(); if (ifNoneMatch == etag) { return shelf.Response.notModified(); } - headers[HttpHeaders.contentLengthHeader] = bytes.length.toString(); + headers[HttpHeaders.contentLengthHeader] = bytes!.length.toString(); headers[HttpHeaders.contentTypeHeader] = 'application/json'; headers[HttpHeaders.etagHeader] = etag; return shelf.Response.ok(bytes, headers: headers); @@ -410,12 +409,12 @@ class WebAssetServer implements AssetReader { // If this is a metadata file, then it might be in the in-memory cache. // Attempt to lookup the file by URI. if (_webMemoryFS.metadataFiles.containsKey(requestPath)) { - final List bytes = getMetadata(requestPath); + final List? bytes = getMetadata(requestPath); final String etag = bytes.hashCode.toString(); if (ifNoneMatch == etag) { return shelf.Response.notModified(); } - headers[HttpHeaders.contentLengthHeader] = bytes.length.toString(); + headers[HttpHeaders.contentLengthHeader] = bytes!.length.toString(); headers[HttpHeaders.contentTypeHeader] = 'application/json'; headers[HttpHeaders.etagHeader] = etag; return shelf.Response.ok(bytes, headers: headers); @@ -475,7 +474,9 @@ class WebAssetServer implements AssetReader { /// Tear down the http server running. Future dispose() async { - await dwds?.stop(); + if (_dwdsInit) { + await dwds.stop(); + } return _httpServer.close(); } @@ -546,7 +547,7 @@ class WebAssetServer implements AssetReader { // The file might have been a package file which is signaled by a // `/packages//` request. if (segments.first == 'packages') { - final Uri filePath = _packages + final Uri? filePath = _packages .resolve(Uri(scheme: 'package', pathSegments: segments.skip(1))); if (filePath != null) { final File packageFile = globals.fs.file(filePath); @@ -559,7 +560,7 @@ class WebAssetServer implements AssetReader { // Otherwise it must be a Dart SDK source or a Flutter Web SDK source. final Directory dartSdkParent = globals.fs .directory( - globals.artifacts.getHostArtifact(HostArtifact.engineDartSdkPath)) + globals.artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath)) .parent; final File dartSdkFile = globals.fs.file(dartSdkParent.uri.resolve(path)); if (dartSdkFile.existsSync()) { @@ -567,25 +568,25 @@ class WebAssetServer implements AssetReader { } final Directory flutterWebSdk = globals.fs - .directory(globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk)); + .directory(globals.artifacts!.getHostArtifact(HostArtifact.flutterWebSdk)); final File webSdkFile = globals.fs.file(flutterWebSdk.uri.resolve(path)); return webSdkFile; } File get _resolveDartSdkJsFile => - globals.fs.file(globals.artifacts.getHostArtifact( - kDartSdkJsArtifactMap[webRenderer][_nullSafetyMode] + globals.fs.file(globals.artifacts!.getHostArtifact( + kDartSdkJsArtifactMap[webRenderer]![_nullSafetyMode]! )); File get _resolveDartSdkJsMapFile => - globals.fs.file(globals.artifacts.getHostArtifact( - kDartSdkJsMapArtifactMap[webRenderer][_nullSafetyMode] + globals.fs.file(globals.artifacts!.getHostArtifact( + kDartSdkJsMapArtifactMap[webRenderer]![_nullSafetyMode]! )); @override - Future dartSourceContents(String serverPath) async { - serverPath = _stripBasePath(serverPath, basePath); + Future dartSourceContents(String serverPath) async { + serverPath = _stripBasePath(serverPath, basePath)!; final File result = _resolveDartFile(serverPath); if (result.existsSync()) { return result.readAsString(); @@ -595,18 +596,18 @@ class WebAssetServer implements AssetReader { @override Future sourceMapContents(String serverPath) async { - serverPath = _stripBasePath(serverPath, basePath); - return utf8.decode(_webMemoryFS.sourcemaps[serverPath]); + serverPath = _stripBasePath(serverPath, basePath)!; + return utf8.decode(_webMemoryFS.sourcemaps[serverPath]!); } @override - Future metadataContents(String serverPath) async { - serverPath = _stripBasePath(serverPath, basePath); - if (serverPath == 'main_module.ddc_merged_metadata') { + Future metadataContents(String serverPath) async { + final String? resultPath = _stripBasePath(serverPath, basePath); + if (resultPath == 'main_module.ddc_merged_metadata') { return _webMemoryFS.mergedMetadata; } - if (_webMemoryFS.metadataFiles.containsKey(serverPath)) { - return utf8.decode(_webMemoryFS.metadataFiles[serverPath]); + if (_webMemoryFS.metadataFiles.containsKey(resultPath)) { + return utf8.decode(_webMemoryFS.metadataFiles[resultPath]!); } throw Exception('Could not find metadata contents for $serverPath'); } @@ -618,8 +619,8 @@ class WebAssetServer implements AssetReader { class ConnectionResult { ConnectionResult(this.appConnection, this.debugConnection, this.vmService); - final AppConnection appConnection; - final DebugConnection debugConnection; + final AppConnection? appConnection; + final DebugConnection? debugConnection; final vm_service.VmService vmService; } @@ -630,29 +631,29 @@ class WebDevFS implements DevFS { /// [testMode] is true, do not actually initialize dwds or the shelf static /// server. WebDevFS({ - @required this.hostname, - @required int port, - @required this.packagesFilePath, - @required this.urlTunneller, - @required this.useSseForDebugProxy, - @required this.useSseForDebugBackend, - @required this.useSseForInjectedClient, - @required this.buildInfo, - @required this.enableDwds, - @required this.enableDds, - @required this.entrypoint, - @required this.expressionCompiler, - @required this.chromiumLauncher, - @required this.nullAssertions, - @required this.nativeNullAssertions, - @required this.nullSafetyMode, + required this.hostname, + required int? port, + required this.packagesFilePath, + required this.urlTunneller, + required this.useSseForDebugProxy, + required this.useSseForDebugBackend, + required this.useSseForInjectedClient, + required this.buildInfo, + required this.enableDwds, + required this.enableDds, + required this.entrypoint, + required this.expressionCompiler, + required this.chromiumLauncher, + required this.nullAssertions, + required this.nativeNullAssertions, + required this.nullSafetyMode, this.testMode = false, }) : _port = port; final Uri entrypoint; final String hostname; final String packagesFilePath; - final UrlTunneller urlTunneller; + final UrlTunneller? urlTunneller; final bool useSseForDebugProxy; final bool useSseForDebugBackend; final bool useSseForInjectedClient; @@ -660,14 +661,14 @@ class WebDevFS implements DevFS { final bool enableDwds; final bool enableDds; final bool testMode; - final ExpressionCompiler expressionCompiler; - final ChromiumLauncher chromiumLauncher; + final ExpressionCompiler? expressionCompiler; + final ChromiumLauncher? chromiumLauncher; final bool nullAssertions; final bool nativeNullAssertions; - final int _port; + final int? _port; final NullSafetyMode nullSafetyMode; - WebAssetServer webAssetServer; + late WebAssetServer webAssetServer; Dwds get dwds => webAssetServer.dwds; @@ -675,13 +676,13 @@ class WebDevFS implements DevFS { @override bool hasSetAssetDirectory = false; - Future _cachedExtensionFuture; - StreamSubscription _connectedApps; + Future? _cachedExtensionFuture; + StreamSubscription? _connectedApps; /// Connect and retrieve the [DebugConnection] for the current application. /// /// Only calls [AppConnection.runMain] on the subsequent connections. - Future connect(bool useDebugExtension) { + Future connect(bool useDebugExtension) { final Completer firstConnection = Completer(); _connectedApps = @@ -706,7 +707,7 @@ class WebDevFS implements DevFS { firstConnection.completeError(error, stackTrace); } } - }, onError: (dynamic error, StackTrace stackTrace) { + }, onError: (Object error, StackTrace stackTrace) { globals.printError( 'Unknown error while waiting for debug connection:$error\n$stackTrace'); if (!firstConnection.isCompleted) { @@ -720,18 +721,18 @@ class WebDevFS implements DevFS { List sources = []; @override - DateTime lastCompiled; + DateTime? lastCompiled; @override - PackageConfig lastPackageConfig; + PackageConfig? lastPackageConfig; // We do not evict assets on the web. @override Set get assetPathsToEvict => const {}; @override - Uri get baseUri => _baseUri; - Uri _baseUri; + Uri? get baseUri => _baseUri; + Uri? _baseUri; @override Future create() async { @@ -758,11 +759,11 @@ class WebDevFS implements DevFS { webAssetServer.webRenderer = WebRendererMode.canvaskit; } if (hostname == 'any') { - _baseUri = Uri.http('localhost:$selectedPort', webAssetServer.basePath); + _baseUri = Uri.http('localhost:$selectedPort', webAssetServer.basePath!); } else { - _baseUri = Uri.http('$hostname:$selectedPort', webAssetServer.basePath); + _baseUri = Uri.http('$hostname:$selectedPort', webAssetServer.basePath!); } - return _baseUri; + return _baseUri!; } @override @@ -780,24 +781,24 @@ class WebDevFS implements DevFS { String get fsName => 'web_asset'; @override - Directory get rootDirectory => null; + Directory? get rootDirectory => null; @override Future update({ - @required Uri mainUri, - @required ResidentCompiler generator, - @required bool trackWidgetCreation, - @required String pathToReload, - @required List invalidatedFiles, - @required PackageConfig packageConfig, - @required String dillOutputPath, - DevFSWriter devFSWriter, - String target, - AssetBundle bundle, - DateTime firstBuildTime, + required Uri mainUri, + required ResidentCompiler generator, + required bool trackWidgetCreation, + required String pathToReload, + required List invalidatedFiles, + required PackageConfig packageConfig, + required String dillOutputPath, + DevFSWriter? devFSWriter, + String? target, + AssetBundle? bundle, + DateTime? firstBuildTime, bool bundleFirstUpload = false, bool fullRestart = false, - String projectRootPath, + String? projectRootPath, }) async { assert(trackWidgetCreation != null); assert(generator != null); @@ -854,7 +855,7 @@ class WebDevFS implements DevFS { // the web specific bootstrap logic. To make it easier for DWDS to handle // mapping the file name, this is done via an additional file root and // special hard-coded scheme. - final CompilerOutput compilerOutput = await generator.recompile( + final CompilerOutput? compilerOutput = await generator.recompile( Uri( scheme: 'org-dartlang-app', path: '/${mainUri.pathSegments.last}', @@ -873,11 +874,11 @@ class WebDevFS implements DevFS { lastCompiled = candidateCompileTime; // list of sources that needs to be monitored are in [compilerOutput.sources] sources = compilerOutput.sources; - File codeFile; + late File codeFile; File manifestFile; File sourcemapFile; File metadataFile; - List modules; + late List modules; try { final Directory parentDirectory = globals.fs.directory(outputDirectoryPath); codeFile = parentDirectory.childFile('${compilerOutput.outputFilename}.sources'); @@ -898,7 +899,7 @@ class WebDevFS implements DevFS { @visibleForTesting final File requireJS = globals.fs.file(globals.fs.path.join( - globals.artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path, + globals.artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath).path, 'lib', 'dev_compiler', 'kernel', @@ -908,7 +909,7 @@ class WebDevFS implements DevFS { @visibleForTesting final File stackTraceMapper = globals.fs.file(globals.fs.path.join( - globals.artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path, + globals.artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath).path, 'lib', 'dev_compiler', 'web', @@ -924,10 +925,10 @@ class WebDevFS implements DevFS { class ReleaseAssetServer { ReleaseAssetServer( this.entrypoint, { - @required FileSystem fileSystem, - @required String webBuildDirectory, - @required String flutterRoot, - @required Platform platform, + required FileSystem fileSystem, + required String? webBuildDirectory, + required String? flutterRoot, + required Platform platform, this.basePath = '', }) : _fileSystem = fileSystem, _platform = platform, @@ -937,8 +938,8 @@ class ReleaseAssetServer { FileSystemUtils(fileSystem: fileSystem, platform: platform); final Uri entrypoint; - final String _flutterRoot; - final String _webBuildDirectory; + final String? _flutterRoot; + final String? _webBuildDirectory; final FileSystem _fileSystem; final FileSystemUtils _fileSystemUtils; final Platform _platform; @@ -948,7 +949,7 @@ class ReleaseAssetServer { /// The base path to serve from. /// /// It should have no leading or trailing slashes. - final String basePath; + final String? basePath; // Locations where source files, assets, or source maps may be located. List _searchPaths() => [ @@ -965,8 +966,8 @@ class ReleaseAssetServer { return shelf.Response.notFound(''); } - Uri fileUri; - final String requestPath = _stripBasePath(request.url.path, basePath); + Uri? fileUri; + final String? requestPath = _stripBasePath(request.url.path, basePath); if (requestPath == null) { return shelf.Response.notFound(''); @@ -1000,7 +1001,7 @@ class ReleaseAssetServer { } final File file = _fileSystem - .file(_fileSystem.path.join(_webBuildDirectory, 'index.html')); + .file(_fileSystem.path.join(_webBuildDirectory!, 'index.html')); return shelf.Response.ok(file.readAsBytesSync(), headers: { 'Content-Type': 'text/html', }); @@ -1022,19 +1023,19 @@ void log(logging.LogRecord event) { Future _loadDwdsDirectory( FileSystem fileSystem, Logger logger) async { final String toolPackagePath = - fileSystem.path.join(Cache.flutterRoot, 'packages', 'flutter_tools'); + fileSystem.path.join(Cache.flutterRoot!, 'packages', 'flutter_tools'); final String packageFilePath = fileSystem.path.join(toolPackagePath, '.dart_tool', 'package_config.json'); final PackageConfig packageConfig = await loadPackageConfigWithLogging( fileSystem.file(packageFilePath), logger: logger, ); - return fileSystem.directory(packageConfig['dwds'].packageUriRoot); + return fileSystem.directory(packageConfig['dwds']!.packageUriRoot); } -String _stripBasePath(String path, String basePath) { +String? _stripBasePath(String path, String? basePath) { path = _stripLeadingSlashes(path); - if (path.startsWith(basePath)) { + if (basePath != null && path.startsWith(basePath)) { path = path.substring(basePath.length); } else { // The given path isn't under base path, return null to indicate that. @@ -1057,25 +1058,25 @@ String _stripTrailingSlashes(String path) { return path; } -String _parseBasePathFromIndexHtml(File indexHtml) { +String? _parseBasePathFromIndexHtml(File indexHtml) { final String htmlContent = indexHtml.existsSync() ? indexHtml.readAsStringSync() : _kDefaultIndex; final Document document = parse(htmlContent); - final Element baseElement = document.querySelector('base'); - String baseHref = - baseElement?.attributes == null ? null : baseElement.attributes['href']; + final Element? baseElement = document.querySelector('base'); + String? baseHref = + baseElement?.attributes == null ? null : baseElement!.attributes['href']; if (baseHref == null || baseHref == kBaseHrefPlaceholder) { baseHref = ''; } else if (!baseHref.startsWith('/')) { throw ToolExit( 'Error: The base href in "web/index.html" must be absolute (i.e. start ' - 'with a "/"), but found: `${baseElement.outerHtml}`.\n' + 'with a "/"), but found: `${baseElement!.outerHtml}`.\n' '$basePathExample', ); } else if (!baseHref.endsWith('/')) { throw ToolExit( - 'Error: The base href in "web/index.html" must end with a "/", but found: `${baseElement.outerHtml}`.\n' + 'Error: The base href in "web/index.html" must end with a "/", but found: `${baseElement!.outerHtml}`.\n' '$basePathExample', ); } else { diff --git a/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart b/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart index 9a5e3c90f8fd..ccb52c41cf0a 100644 --- a/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart +++ b/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart @@ -2,12 +2,10 @@ // 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'; +// ignore: import_of_legacy_library_into_null_safe import 'package:dwds/dwds.dart'; -import 'package:meta/meta.dart'; import 'package:package_config/package_config.dart'; import 'package:vm_service/vm_service.dart' as vmservice; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' @@ -48,16 +46,16 @@ class DwdsWebRunnerFactory extends WebRunnerFactory { @override ResidentRunner createWebRunner( FlutterDevice device, { - String target, - @required bool stayResident, - @required FlutterProject flutterProject, - @required bool ipv6, - @required DebuggingOptions debuggingOptions, - @required UrlTunneller urlTunneller, - @required Logger logger, - @required FileSystem fileSystem, - @required SystemClock systemClock, - @required Usage usage, + String? target, + required bool stayResident, + required FlutterProject flutterProject, + required bool? ipv6, + required DebuggingOptions debuggingOptions, + required UrlTunneller? urlTunneller, + required Logger? logger, + required FileSystem fileSystem, + required SystemClock systemClock, + required Usage usage, bool machine = false, }) { return ResidentWebRunner( @@ -83,18 +81,18 @@ const String kExitMessage = 'Failed to establish connection with the application class ResidentWebRunner extends ResidentRunner { ResidentWebRunner( - FlutterDevice device, { - String target, + FlutterDevice? device, { + String? target, bool stayResident = true, bool machine = false, - @required this.flutterProject, - @required bool ipv6, - @required DebuggingOptions debuggingOptions, - @required FileSystem fileSystem, - @required Logger logger, - @required SystemClock systemClock, - @required Usage usage, - @required UrlTunneller urlTunneller, + required this.flutterProject, + required bool? ipv6, + required DebuggingOptions debuggingOptions, + required FileSystem? fileSystem, + required Logger? logger, + required SystemClock systemClock, + required Usage usage, + UrlTunneller? urlTunneller, ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler, }) : _fileSystem = fileSystem, _logger = logger, @@ -102,8 +100,8 @@ class ResidentWebRunner extends ResidentRunner { _usage = usage, _urlTunneller = urlTunneller, super( - [device], - target: target ?? fileSystem.path.join('lib', 'main.dart'), + [device], + target: target ?? fileSystem!.path.join('lib', 'main.dart'), debuggingOptions: debuggingOptions, ipv6: ipv6, stayResident: stayResident, @@ -111,25 +109,25 @@ class ResidentWebRunner extends ResidentRunner { devtoolsHandler: devtoolsHandler, ); - final FileSystem _fileSystem; - final Logger _logger; + final FileSystem? _fileSystem; + final Logger? _logger; final SystemClock _systemClock; final Usage _usage; - final UrlTunneller _urlTunneller; + final UrlTunneller? _urlTunneller; @override - Logger get logger => _logger; + Logger? get logger => _logger; @override - FileSystem get fileSystem => _fileSystem; + FileSystem? get fileSystem => _fileSystem; - FlutterDevice get device => flutterDevices.first; + FlutterDevice? get device => flutterDevices.first; final FlutterProject flutterProject; - DateTime firstBuildTime; + DateTime? firstBuildTime; // Used with the new compiler to generate a bootstrap file containing plugins // and platform initialization. - Directory _generatedEntrypointDirectory; + Directory? _generatedEntrypointDirectory; // Only the debug builds of the web support the service protocol. @override @@ -139,7 +137,7 @@ class ResidentWebRunner extends ResidentRunner { bool get debuggingEnabled => isRunningDebug && deviceIsDebuggable; /// WebServer device is debuggable when running with --start-paused. - bool get deviceIsDebuggable => device.device is! WebServerDevice || debuggingOptions.startPaused; + bool get deviceIsDebuggable => device!.device is! WebServerDevice || debuggingOptions.startPaused; @override bool get supportsWriteSkSL => false; @@ -150,24 +148,24 @@ class ResidentWebRunner extends ResidentRunner { bool get _enableDwds => debuggingEnabled; - ConnectionResult _connectionResult; - StreamSubscription _stdOutSub; - StreamSubscription _stdErrSub; - StreamSubscription _extensionEventSub; + ConnectionResult? _connectionResult; + StreamSubscription? _stdOutSub; + StreamSubscription? _stdErrSub; + StreamSubscription? _extensionEventSub; bool _exited = false; - WipConnection _wipConnection; - ChromiumLauncher _chromiumLauncher; + WipConnection? _wipConnection; + ChromiumLauncher? _chromiumLauncher; FlutterVmService get _vmService { if (_instance != null) { - return _instance; + return _instance!; } - final vmservice.VmService service =_connectionResult?.vmService; - final Uri websocketUri = Uri.parse(_connectionResult.debugConnection.uri); + final vmservice.VmService? service =_connectionResult?.vmService; + final Uri websocketUri = Uri.parse(_connectionResult!.debugConnection!.uri); final Uri httpUri = _httpUriFromWebsocketUri(websocketUri); - return _instance ??= FlutterVmService(service, wsAddress: websocketUri, httpAddress: httpUri); + return _instance ??= FlutterVmService(service!, wsAddress: websocketUri, httpAddress: httpUri); } - FlutterVmService _instance; + FlutterVmService? _instance; @override Future cleanupAfterSignal() async { @@ -183,17 +181,17 @@ class ResidentWebRunner extends ResidentRunner { if (_exited) { return; } - await residentDevtoolsHandler.shutdown(); + await residentDevtoolsHandler!.shutdown(); await _stdOutSub?.cancel(); await _stdErrSub?.cancel(); await _extensionEventSub?.cancel(); - await device.device.stopApp(null); + await device!.device!.stopApp(null); try { _generatedEntrypointDirectory?.deleteSync(recursive: true); } on FileSystemException { // Best effort to clean up temp dirs. - _logger.printTrace( - 'Failed to clean up temp directory: ${_generatedEntrypointDirectory.path}', + _logger!.printTrace( + 'Failed to clean up temp directory: ${_generatedEntrypointDirectory!.path}', ); } _exited = true; @@ -212,59 +210,58 @@ class ResidentWebRunner extends ResidentRunner { const String fire = '🔥'; const String rawMessage = ' To hot restart changes while running, press "r" or "R".'; - final String message = _logger.terminal.color( - fire + _logger.terminal.bolden(rawMessage), + final String message = _logger!.terminal.color( + fire + _logger!.terminal.bolden(rawMessage), TerminalColor.red, ); - _logger.printStatus(message); + _logger!.printStatus(message); const String quitMessage = 'To quit, press "q".'; - _logger.printStatus('For a more detailed help message, press "h". $quitMessage'); - _logger.printStatus(''); + _logger!.printStatus('For a more detailed help message, press "h". $quitMessage'); + _logger!.printStatus(''); printDebuggerList(); } @override Future stopEchoingDeviceLog() async { // Do nothing for ResidentWebRunner - await device.stopEchoingDeviceLog(); + await device!.stopEchoingDeviceLog(); } @override Future run({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, bool enableDevTools = false, // ignored, we don't yet support devtools for web - String route, + String? route, }) async { firstBuildTime = DateTime.now(); - final ApplicationPackage package = await ApplicationPackageFactory.instance.getPackageForPlatform( + final ApplicationPackage? package = await ApplicationPackageFactory.instance!.getPackageForPlatform( TargetPlatform.web_javascript, buildInfo: debuggingOptions.buildInfo, - applicationBinary: null, ); if (package == null) { - _logger.printStatus('This application is not configured to build on the web.'); - _logger.printStatus('To add web support to a project, run `flutter create .`.'); + _logger!.printStatus('This application is not configured to build on the web.'); + _logger!.printStatus('To add web support to a project, run `flutter create .`.'); } final String modeName = debuggingOptions.buildInfo.friendlyModeName; - _logger.printStatus( - 'Launching ${getDisplayPath(target, _fileSystem)} ' - 'on ${device.device.name} in $modeName mode...', + _logger!.printStatus( + 'Launching ${getDisplayPath(target, _fileSystem!)} ' + 'on ${device!.device!.name} in $modeName mode...', ); - if (device.device is ChromiumDevice) { - _chromiumLauncher = (device.device as ChromiumDevice).chromeLauncher; + if (device!.device is ChromiumDevice) { + _chromiumLauncher = (device!.device! as ChromiumDevice).chromeLauncher; } try { return await asyncGuard(() async { - final ExpressionCompiler expressionCompiler = + final ExpressionCompiler? expressionCompiler = debuggingOptions.webEnableExpressionEvaluation - ? WebExpressionCompiler(device.generator, fileSystem: _fileSystem) + ? WebExpressionCompiler(device!.generator!, fileSystem: _fileSystem) : null; - device.devFS = WebDevFS( + device!.devFS = WebDevFS( hostname: debuggingOptions.hostname ?? 'localhost', port: debuggingOptions.port != null - ? int.tryParse(debuggingOptions.port) + ? int.tryParse(debuggingOptions.port!) : null, packagesFilePath: packagesFilePath, urlTunneller: _urlTunneller, @@ -274,22 +271,22 @@ class ResidentWebRunner extends ResidentRunner { buildInfo: debuggingOptions.buildInfo, enableDwds: _enableDwds, enableDds: debuggingOptions.enableDds, - entrypoint: _fileSystem.file(target).uri, + entrypoint: _fileSystem!.file(target).uri, expressionCompiler: expressionCompiler, chromiumLauncher: _chromiumLauncher, nullAssertions: debuggingOptions.nullAssertions, nullSafetyMode: debuggingOptions.buildInfo.nullSafetyMode, nativeNullAssertions: debuggingOptions.nativeNullAssertions, ); - final Uri url = await device.devFS.create(); + final Uri url = await device!.devFS!.create(); if (debuggingOptions.buildInfo.isDebug) { final UpdateFSReport report = await _updateDevFS(fullRestart: true); if (!report.success) { - _logger.printError('Failed to compile application.'); + _logger!.printError('Failed to compile application.'); appFailedToStart(); return 1; } - device.generator.accept(); + device!.generator!.accept(); cacheInitialDillCompilation(); } else { await buildWeb( @@ -304,7 +301,7 @@ class ResidentWebRunner extends ResidentRunner { null, ); } - await device.device.startApp( + await device!.device!.startApp( package, mainPath: target, debuggingOptions: debuggingOptions, @@ -320,19 +317,19 @@ class ResidentWebRunner extends ResidentRunner { }); } on WebSocketException catch (error, stackTrace) { appFailedToStart(); - _logger.printError('$error', stackTrace: stackTrace); + _logger!.printError('$error', stackTrace: stackTrace); throwToolExit(kExitMessage); } on ChromeDebugException catch (error, stackTrace) { appFailedToStart(); - _logger.printError('$error', stackTrace: stackTrace); + _logger!.printError('$error', stackTrace: stackTrace); throwToolExit(kExitMessage); } on AppConnectionException catch (error, stackTrace) { appFailedToStart(); - _logger.printError('$error', stackTrace: stackTrace); + _logger!.printError('$error', stackTrace: stackTrace); throwToolExit(kExitMessage); } on SocketException catch (error, stackTrace) { appFailedToStart(); - _logger.printError('$error', stackTrace: stackTrace); + _logger!.printError('$error', stackTrace: stackTrace); throwToolExit(kExitMessage); } on Exception { appFailedToStart(); @@ -343,12 +340,12 @@ class ResidentWebRunner extends ResidentRunner { @override Future restart({ bool fullRestart = false, - bool pause = false, - String reason, + bool? pause = false, + String? reason, bool benchmarkMode = false, }) async { final DateTime start = _systemClock.now(); - final Status status = _logger.startProgress( + final Status status = _logger!.startProgress( 'Performing hot restart...', progressId: 'hot.restart', ); @@ -358,10 +355,10 @@ class ResidentWebRunner extends ResidentRunner { // Full restart is always false for web, since the extra recompile is wasteful. final UpdateFSReport report = await _updateDevFS(); if (report.success) { - device.generator.accept(); + device!.generator!.accept(); } else { status.stop(); - await device.generator.reject(); + await device!.generator!.reject(); return OperationResult(1, 'Failed to recompile application.'); } } else { @@ -384,7 +381,7 @@ class ResidentWebRunner extends ResidentRunner { try { if (!deviceIsDebuggable) { - _logger.printStatus('Recompile complete. Page requires refresh.'); + _logger!.printStatus('Recompile complete. Page requires refresh.'); } else if (isRunningDebug) { await _vmService.service.callMethod('hotRestart'); } else { @@ -402,8 +399,8 @@ class ResidentWebRunner extends ResidentRunner { final Duration elapsed = _systemClock.now().difference(start); final String elapsedMS = getElapsedAsMilliseconds(elapsed); - _logger.printStatus('Restarted application in $elapsedMS.'); - unawaited(residentDevtoolsHandler.hotRestart(flutterDevices)); + _logger!.printStatus('Restarted application in $elapsedMS.'); + unawaited(residentDevtoolsHandler!.hotRestart(flutterDevices)); // Don't track restart times for dart2js builds or web-server devices. if (debuggingOptions.buildInfo.isDebug && deviceIsDebuggable) { @@ -411,7 +408,7 @@ class ResidentWebRunner extends ResidentRunner { HotEvent( 'restart', targetPlatform: getNameForTargetPlatform(TargetPlatform.web_javascript), - sdkName: await device.device.sdkNameAndVersion, + sdkName: await device!.device!.sdkNameAndVersion, emulator: false, fullRestart: true, reason: reason, @@ -425,34 +422,34 @@ class ResidentWebRunner extends ResidentRunner { // Flutter web projects need to include a generated main entrypoint to call the // appropriate bootstrap method and inject plugins. // Keep this in sync with build_system/targets/web.dart. - Future _generateEntrypoint(Uri mainUri, PackageConfig packageConfig) async { - File result = _generatedEntrypointDirectory?.childFile('web_entrypoint.dart'); + Future _generateEntrypoint(Uri mainUri, PackageConfig? packageConfig) async { + File? result = _generatedEntrypointDirectory?.childFile('web_entrypoint.dart'); if (_generatedEntrypointDirectory == null) { - _generatedEntrypointDirectory ??= _fileSystem.systemTempDirectory.createTempSync('flutter_tools.') + _generatedEntrypointDirectory ??= _fileSystem!.systemTempDirectory.createTempSync('flutter_tools.') ..createSync(); - result = _generatedEntrypointDirectory.childFile('web_entrypoint.dart'); + result = _generatedEntrypointDirectory!.childFile('web_entrypoint.dart'); // Generates the generated_plugin_registrar - await injectBuildTimePluginFiles(flutterProject, webPlatform: true, destination: _generatedEntrypointDirectory); + await injectBuildTimePluginFiles(flutterProject, webPlatform: true, destination: _generatedEntrypointDirectory!); // The below works because `injectBuildTimePluginFiles` is configured to write // the web_plugin_registrant.dart file alongside the generated main.dart - const String/*?*/ generatedImport = 'web_plugin_registrant.dart'; + const String generatedImport = 'web_plugin_registrant.dart'; - Uri importedEntrypoint = packageConfig.toPackageUri(mainUri); + Uri? importedEntrypoint = packageConfig!.toPackageUri(mainUri); // Special handling for entrypoints that are not under lib, such as test scripts. if (importedEntrypoint == null) { - final String parent = _fileSystem.file(mainUri).parent.path; - flutterDevices.first.generator.addFileSystemRoot(parent); - flutterDevices.first.generator.addFileSystemRoot(_fileSystem.directory('test').absolute.path); + final String parent = _fileSystem!.file(mainUri).parent.path; + flutterDevices.first!.generator!.addFileSystemRoot(parent); + flutterDevices.first!.generator!.addFileSystemRoot(_fileSystem!.directory('test').absolute.path); importedEntrypoint = Uri( scheme: 'org-dartlang-app', path: '/${mainUri.pathSegments.last}', ); } final LanguageVersion languageVersion = determineLanguageVersion( - _fileSystem.file(mainUri), + _fileSystem!.file(mainUri), packageConfig[flutterProject.manifest.appName], - Cache.flutterRoot, + Cache.flutterRoot!, ); final String entrypoint = main_dart.generateMainDartFile(importedEntrypoint.toString(), @@ -462,14 +459,14 @@ class ResidentWebRunner extends ResidentRunner { result.writeAsStringSync(entrypoint); } - return result.absolute.uri; + return result!.absolute.uri; } Future _updateDevFS({bool fullRestart = false}) async { final bool isFirstUpload = !assetBundle.wasBuiltOnce(); final bool rebuildBundle = assetBundle.needsBuild(); if (rebuildBundle) { - _logger.printTrace('Updating assets'); + _logger!.printTrace('Updating assets'); final int result = await assetBundle.build( packagesPath: debuggingOptions.buildInfo.packagesPath, targetPlatform: TargetPlatform.web_javascript, @@ -479,67 +476,66 @@ class ResidentWebRunner extends ResidentRunner { } } final InvalidationResult invalidationResult = await projectFileInvalidator.findInvalidated( - lastCompiled: device.devFS.lastCompiled, - urisToMonitor: device.devFS.sources, + lastCompiled: device!.devFS!.lastCompiled, + urisToMonitor: device!.devFS!.sources, packagesPath: packagesFilePath, - packageConfig: device.devFS.lastPackageConfig + packageConfig: device!.devFS!.lastPackageConfig ?? debuggingOptions.buildInfo.packageConfig, ); - final Status devFSStatus = _logger.startProgress( - 'Waiting for connection from debug service on ${device.device.name}...', + final Status devFSStatus = _logger!.startProgress( + 'Waiting for connection from debug service on ${device!.device!.name}...', ); - final UpdateFSReport report = await device.devFS.update( + final UpdateFSReport report = await device!.devFS!.update( mainUri: await _generateEntrypoint( - _fileSystem.file(mainPath).absolute.uri, + _fileSystem!.file(mainPath).absolute.uri, invalidationResult.packageConfig, ), target: target, bundle: assetBundle, firstBuildTime: firstBuildTime, bundleFirstUpload: isFirstUpload, - generator: device.generator, + generator: device!.generator!, fullRestart: fullRestart, dillOutputPath: dillOutputPath, projectRootPath: projectRootPath, pathToReload: getReloadPath(fullRestart: fullRestart, swap: false), - invalidatedFiles: invalidationResult.uris, - packageConfig: invalidationResult.packageConfig, + invalidatedFiles: invalidationResult.uris!, + packageConfig: invalidationResult.packageConfig!, trackWidgetCreation: debuggingOptions.buildInfo.trackWidgetCreation, - devFSWriter: null, ); devFSStatus.stop(); - _logger.printTrace('Synced ${getSizeAsMB(report.syncedBytes)}.'); + _logger!.printTrace('Synced ${getSizeAsMB(report.syncedBytes)}.'); return report; } @override Future attach({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, bool allowExistingDdsInstance = false, bool enableDevTools = false, // ignored, we don't yet support devtools for web bool needsFullRestart = true, }) async { if (_chromiumLauncher != null) { - final Chromium chrome = await _chromiumLauncher.connectedInstance; - final ChromeTab chromeTab = await chrome.chromeConnection.getTab((ChromeTab chromeTab) { + final Chromium chrome = await _chromiumLauncher!.connectedInstance; + final ChromeTab chromeTab = await (chrome.chromeConnection.getTab((ChromeTab chromeTab) { return !chromeTab.url.startsWith('chrome-extension'); - }); + }) as FutureOr); if (chromeTab == null) { throwToolExit('Failed to connect to Chrome instance.'); } _wipConnection = await chromeTab.connect(); } - Uri websocketUri; + Uri? websocketUri; if (supportsServiceProtocol) { - final WebDevFS webDevFS = device.devFS as WebDevFS; - final bool useDebugExtension = device.device is WebServerDevice && debuggingOptions.startPaused; + final WebDevFS webDevFS = device!.devFS! as WebDevFS; + final bool useDebugExtension = device!.device is WebServerDevice && debuggingOptions.startPaused; _connectionResult = await webDevFS.connect(useDebugExtension); - unawaited(_connectionResult.debugConnection.onDone.whenComplete(_cleanupAndExit)); + unawaited(_connectionResult!.debugConnection!.onDone.whenComplete(_cleanupAndExit)); void onLogEvent(vmservice.Event event) { final String message = processVmServiceMessage(event); - _logger.printStatus(message); + _logger!.printStatus(message); } _stdOutSub = _vmService.service.onStdoutEvent.listen(onLogEvent); @@ -564,41 +560,41 @@ class ResidentWebRunner extends ResidentRunner { } await setUpVmService( (String isolateId, { - bool force, - bool pause, + bool? force, + bool? pause, }) async { await restart(pause: pause); }, null, null, - device.device, + device!.device, null, printStructuredErrorLog, _vmService.service, ); - websocketUri = Uri.parse(_connectionResult.debugConnection.uri); - device.vmService = _vmService; + websocketUri = Uri.parse(_connectionResult!.debugConnection!.uri); + device!.vmService = _vmService; // Run main immediately if the app is not started paused or if there // is no debugger attached. Otherwise, runMain when a resume event // is received. if (!debuggingOptions.startPaused || !supportsServiceProtocol) { - _connectionResult.appConnection.runMain(); + _connectionResult!.appConnection!.runMain(); } else { - StreamSubscription resumeSub; + late StreamSubscription resumeSub; resumeSub = _vmService.service.onDebugEvent .listen((vmservice.Event event) { if (event.type == vmservice.EventKind.kResume) { - _connectionResult.appConnection.runMain(); + _connectionResult!.appConnection!.runMain(); resumeSub.cancel(); } }); } if (enableDevTools) { // The method below is guaranteed never to return a failing future. - unawaited(residentDevtoolsHandler.serveAndAnnounceDevTools( + unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools( devToolsServerAddress: debuggingOptions.devToolsServerAddress, flutterDevices: flutterDevices, )); @@ -606,20 +602,20 @@ class ResidentWebRunner extends ResidentRunner { } if (websocketUri != null) { if (debuggingOptions.vmserviceOutFile != null) { - _fileSystem.file(debuggingOptions.vmserviceOutFile) + _fileSystem!.file(debuggingOptions.vmserviceOutFile) ..createSync(recursive: true) ..writeAsStringSync(websocketUri.toString()); } - _logger.printStatus('Debug service listening on $websocketUri'); - _logger.printStatus(''); + _logger!.printStatus('Debug service listening on $websocketUri'); + _logger!.printStatus(''); if (debuggingOptions.buildInfo.nullSafetyMode == NullSafetyMode.sound) { - _logger.printStatus('💪 Running with sound null safety 💪', emphasis: true); + _logger!.printStatus('💪 Running with sound null safety 💪', emphasis: true); } else { - _logger.printStatus( + _logger!.printStatus( 'Running with unsound null safety', emphasis: true, ); - _logger.printStatus( + _logger!.printStatus( 'For more information see https://dart.dev/null-safety/unsound-null-safety', ); } @@ -638,7 +634,7 @@ class ResidentWebRunner extends ResidentRunner { @override Future exitApp() async { - await device.exitApps(); + await device!.exitApps(); appFinished(); } } diff --git a/packages/flutter_tools/lib/src/isolated/sdk_web_configuration.dart b/packages/flutter_tools/lib/src/isolated/sdk_web_configuration.dart index 0852cf4e90d4..9e17b3af79bc 100644 --- a/packages/flutter_tools/lib/src/isolated/sdk_web_configuration.dart +++ b/packages/flutter_tools/lib/src/isolated/sdk_web_configuration.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 'dart:async'; +// ignore: import_of_legacy_library_into_null_safe import 'package:dwds/dwds.dart'; import '../artifacts.dart'; @@ -17,12 +16,12 @@ class SdkWebConfigurationProvider extends SdkConfigurationProvider { SdkWebConfigurationProvider(this._artifacts); final Artifacts _artifacts; - SdkConfiguration _configuration; + SdkConfiguration? _configuration; /// Create and validate configuration matching the default SDK layout. /// Create configuration matching the default SDK layout. @override - Future get configuration async { + Future get configuration async { if (_configuration == null) { final String sdkDir = _artifacts.getHostArtifact(HostArtifact.flutterWebSdk).path; final String unsoundSdkSummaryPath = _artifacts.getHostArtifact(HostArtifact.webPlatformKernelDill).path; @@ -40,7 +39,7 @@ class SdkWebConfigurationProvider extends SdkConfigurationProvider { } /// Validate that SDK configuration exists on disk. - static void validate(SdkConfiguration configuration, { FileSystem fileSystem }) { + static void validate(SdkConfiguration configuration, { required FileSystem fileSystem }) { configuration.validateSdkDir(fileSystem: fileSystem); configuration.validateSummaries(fileSystem: fileSystem); configuration.validateLibrariesSpec(fileSystem: fileSystem); diff --git a/packages/flutter_tools/lib/src/preview_device.dart b/packages/flutter_tools/lib/src/preview_device.dart index fe00f0bd31a0..c37a55cdfb6a 100644 --- a/packages/flutter_tools/lib/src/preview_device.dart +++ b/packages/flutter_tools/lib/src/preview_device.dart @@ -181,7 +181,7 @@ class PreviewDevice extends Device { } @override - DevFSWriter createDevFSWriter(covariant ApplicationPackage app, String userIdentifier) { + DevFSWriter createDevFSWriter(covariant ApplicationPackage? app, String? userIdentifier) { return LocalDevFSWriter(fileSystem: _fileSystem); } } diff --git a/packages/flutter_tools/lib/src/resident_devtools_handler.dart b/packages/flutter_tools/lib/src/resident_devtools_handler.dart index 98c00c381824..6f3ccb61e9f7 100644 --- a/packages/flutter_tools/lib/src/resident_devtools_handler.dart +++ b/packages/flutter_tools/lib/src/resident_devtools_handler.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 'package:browser_launcher/browser_launcher.dart'; @@ -14,9 +12,9 @@ import 'build_info.dart'; import 'resident_runner.dart'; import 'vmservice.dart'; -typedef ResidentDevtoolsHandlerFactory = ResidentDevtoolsHandler Function(DevtoolsLauncher, ResidentRunner, Logger); +typedef ResidentDevtoolsHandlerFactory = ResidentDevtoolsHandler Function(DevtoolsLauncher?, ResidentRunner, Logger); -ResidentDevtoolsHandler createDefaultHandler(DevtoolsLauncher launcher, ResidentRunner runner, Logger logger) { +ResidentDevtoolsHandler createDefaultHandler(DevtoolsLauncher? launcher, ResidentRunner runner, Logger logger) { return FlutterResidentDevtoolsHandler(launcher, runner, logger); } @@ -24,7 +22,7 @@ ResidentDevtoolsHandler createDefaultHandler(DevtoolsLauncher launcher, Resident /// the resident runner. abstract class ResidentDevtoolsHandler { /// The current devtools server, or null if one is not running. - DevToolsServerAddress get activeDevToolsServer; + DevToolsServerAddress? get activeDevToolsServer; /// Whether it's ok to announce the [activeDevToolsServer]. /// @@ -32,14 +30,14 @@ abstract class ResidentDevtoolsHandler { /// of the DevTools. bool get readyToAnnounce; - Future hotRestart(List flutterDevices); + Future hotRestart(List flutterDevices); Future serveAndAnnounceDevTools({ - Uri devToolsServerAddress, - @required List flutterDevices, + Uri? devToolsServerAddress, + required List flutterDevices, }); - bool launchDevToolsInBrowser({@required List flutterDevices}); + bool launchDevToolsInBrowser({required List flutterDevices}); Future shutdown(); } @@ -49,7 +47,7 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { static const Duration launchInBrowserTimeout = Duration(seconds: 15); - final DevtoolsLauncher _devToolsLauncher; + final DevtoolsLauncher? _devToolsLauncher; final ResidentRunner _residentRunner; final Logger _logger; bool _shutdown = false; @@ -59,7 +57,7 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { bool launchedInBrowser = false; @override - DevToolsServerAddress get activeDevToolsServer { + DevToolsServerAddress? get activeDevToolsServer { assert(!_readyToAnnounce || _devToolsLauncher?.activeDevToolsServer != null); return _devToolsLauncher?.activeDevToolsServer; } @@ -71,26 +69,26 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { // This must be guaranteed not to return a Future that fails. @override Future serveAndAnnounceDevTools({ - Uri devToolsServerAddress, - @required List flutterDevices, + Uri? devToolsServerAddress, + required List flutterDevices, }) async { assert(!_readyToAnnounce); if (!_residentRunner.supportsServiceProtocol || _devToolsLauncher == null) { return; } if (devToolsServerAddress != null) { - _devToolsLauncher.devToolsUrl = devToolsServerAddress; + _devToolsLauncher!.devToolsUrl = devToolsServerAddress; } else { - await _devToolsLauncher.serve(); + await _devToolsLauncher!.serve(); _served = true; } - await _devToolsLauncher.ready; + await _devToolsLauncher!.ready; // Do not attempt to print debugger list if the connection has failed or if we're shutting down. - if (_devToolsLauncher.activeDevToolsServer == null || _shutdown) { + if (_devToolsLauncher!.activeDevToolsServer == null || _shutdown) { assert(!_readyToAnnounce); return; } - final List devicesWithExtension = await _devicesWithExtensions(flutterDevices); + final List devicesWithExtension = await _devicesWithExtensions(flutterDevices); await _maybeCallDevToolsUriServiceExtension(devicesWithExtension); await _callConnectedVmServiceUriExtension(devicesWithExtension); if (_shutdown) { @@ -98,7 +96,7 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { return; } _readyToAnnounce = true; - assert(_devToolsLauncher.activeDevToolsServer != null); + assert(_devToolsLauncher!.activeDevToolsServer != null); if (_residentRunner.reportedDebuggers) { // Since the DevTools only just became available, we haven't had a chance to // report their URLs yet. Do so now. @@ -108,13 +106,13 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { // This must be guaranteed not to return a Future that fails. @override - bool launchDevToolsInBrowser({@required List flutterDevices}) { + bool launchDevToolsInBrowser({required List flutterDevices}) { if (!_residentRunner.supportsServiceProtocol || _devToolsLauncher == null) { return false; } - if (_devToolsLauncher.devToolsUrl == null) { + if (_devToolsLauncher!.devToolsUrl == null) { _logger.startProgress('Waiting for Flutter DevTools to be served...'); - unawaited(_devToolsLauncher.ready.then((_) { + unawaited(_devToolsLauncher!.ready.then((_) { _launchDevToolsForDevices(flutterDevices); })); } else { @@ -123,27 +121,27 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { return true; } - void _launchDevToolsForDevices(List flutterDevices) { + void _launchDevToolsForDevices(List flutterDevices) { assert(activeDevToolsServer != null); - for (final FlutterDevice device in flutterDevices) { - final String devToolsUrl = activeDevToolsServer.uri?.replace( - queryParameters: {'uri': '${device.vmService.httpAddress}'}, + for (final FlutterDevice? device in flutterDevices) { + final String devToolsUrl = activeDevToolsServer!.uri!.replace( + queryParameters: {'uri': '${device!.vmService!.httpAddress}'}, ).toString(); - _logger.printStatus('Launching Flutter DevTools for ${device.device.name} at $devToolsUrl'); + _logger.printStatus('Launching Flutter DevTools for ${device.device!.name} at $devToolsUrl'); unawaited(Chrome.start([devToolsUrl])); } launchedInBrowser = true; } Future _maybeCallDevToolsUriServiceExtension( - List flutterDevices, + List flutterDevices, ) async { if (_devToolsLauncher?.activeDevToolsServer == null) { return; } await Future.wait(>[ - for (final FlutterDevice device in flutterDevices) - if (device.vmService != null) _callDevToolsUriExtension(device), + for (final FlutterDevice? device in flutterDevices) + if (device?.vmService != null) _callDevToolsUriExtension(device!), ]); } @@ -155,7 +153,7 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { 'ext.flutter.activeDevToolsServerAddress', device: device, params: { - 'value': _devToolsLauncher.activeDevToolsServer.uri.toString(), + 'value': _devToolsLauncher!.activeDevToolsServer!.uri.toString(), }, ); } on Exception catch (e) { @@ -166,15 +164,14 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { } } - Future> _devicesWithExtensions(List flutterDevices) async { - final List devices = await Future.wait(>[ - for (final FlutterDevice device in flutterDevices) _waitForExtensionsForDevice(device), + Future> _devicesWithExtensions(List flutterDevices) async { + return Future.wait(>[ + for (final FlutterDevice? device in flutterDevices) _waitForExtensionsForDevice(device!), ]); - return devices.where((FlutterDevice device) => device != null).toList(); } /// Returns null if the service extension cannot be found on the device. - Future _waitForExtensionsForDevice(FlutterDevice flutterDevice) async { + Future _waitForExtensionsForDevice(FlutterDevice flutterDevice) async { const String extension = 'ext.flutter.connectedVmServiceUri'; try { await flutterDevice.vmService?.findExtensionIsolate( @@ -191,15 +188,15 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { } } - Future _callConnectedVmServiceUriExtension(List flutterDevices) async { + Future _callConnectedVmServiceUriExtension(List flutterDevices) async { await Future.wait(>[ - for (final FlutterDevice device in flutterDevices) - if (device.vmService != null) _callConnectedVmServiceExtension(device), + for (final FlutterDevice? device in flutterDevices) + if (device?.vmService != null) _callConnectedVmServiceExtension(device!), ]); } Future _callConnectedVmServiceExtension(FlutterDevice device) async { - final Uri uri = device.vmService.httpAddress ?? device.vmService.wsAddress; + final Uri? uri = device.vmService!.httpAddress ?? device.vmService!.wsAddress; if (uri == null) { return; } @@ -222,29 +219,30 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { Future _invokeRpcOnFirstView( String method, { - @required FlutterDevice device, - @required Map params, + required FlutterDevice device, + required Map params, }) async { if (device.targetPlatform == TargetPlatform.web_javascript) { - return device.vmService.callMethodWrapper( + await device.vmService!.callMethodWrapper( method, args: params, ); + return; } - final List views = await device.vmService.getFlutterViews(); + final List views = await device.vmService!.getFlutterViews(); if (views.isEmpty) { return; } - await device.vmService.invokeFlutterExtensionRpcRaw( + await device.vmService!.invokeFlutterExtensionRpcRaw( method, args: params, - isolateId: views.first.uiIsolate.id, + isolateId: views.first.uiIsolate!.id!, ); } @override - Future hotRestart(List flutterDevices) async { - final List devicesWithExtension = await _devicesWithExtensions(flutterDevices); + Future hotRestart(List flutterDevices) async { + final List devicesWithExtension = await _devicesWithExtensions(flutterDevices); await Future.wait(>[ _maybeCallDevToolsUriServiceExtension(devicesWithExtension), _callConnectedVmServiceUriExtension(devicesWithExtension), @@ -258,12 +256,12 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { } _shutdown = true; _readyToAnnounce = false; - await _devToolsLauncher.close(); + await _devToolsLauncher!.close(); } } @visibleForTesting -NoOpDevtoolsHandler createNoOpHandler(DevtoolsLauncher launcher, ResidentRunner runner, Logger logger) { +NoOpDevtoolsHandler createNoOpHandler(DevtoolsLauncher? launcher, ResidentRunner runner, Logger logger) { return NoOpDevtoolsHandler(); } @@ -272,23 +270,23 @@ class NoOpDevtoolsHandler implements ResidentDevtoolsHandler { bool wasShutdown = false; @override - DevToolsServerAddress get activeDevToolsServer => null; + DevToolsServerAddress? get activeDevToolsServer => null; @override bool get readyToAnnounce => false; @override - Future hotRestart(List flutterDevices) async { + Future hotRestart(List flutterDevices) async { return; } @override - Future serveAndAnnounceDevTools({Uri devToolsServerAddress, List flutterDevices}) async { + Future serveAndAnnounceDevTools({Uri? devToolsServerAddress, List? flutterDevices}) async { return; } @override - bool launchDevToolsInBrowser({List flutterDevices}) { + bool launchDevToolsInBrowser({List? flutterDevices}) { return false; } diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 1774909763e6..8a0312c00f1e 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.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 'package:dds/dds.dart' as dds; @@ -46,27 +44,27 @@ import 'vmservice.dart'; class FlutterDevice { FlutterDevice( this.device, { - @required this.buildInfo, + required this.buildInfo, TargetModel targetModel = TargetModel.flutter, this.targetPlatform, - ResidentCompiler generator, + ResidentCompiler? generator, this.userIdentifier, }) : assert(buildInfo.trackWidgetCreation != null), generator = generator ?? ResidentCompiler( - globals.artifacts.getArtifactPath( + globals.artifacts!.getArtifactPath( Artifact.flutterPatchedSdkPath, platform: targetPlatform, mode: buildInfo.mode, ), buildMode: buildInfo.mode, trackWidgetCreation: buildInfo.trackWidgetCreation, - fileSystemRoots: buildInfo.fileSystemRoots ?? [], + fileSystemRoots: buildInfo.fileSystemRoots, fileSystemScheme: buildInfo.fileSystemScheme, targetModel: targetModel, dartDefines: buildInfo.dartDefines, packagesPath: buildInfo.packagesPath, extraFrontEndOptions: buildInfo.extraFrontEndOptions, - artifacts: globals.artifacts, + artifacts: globals.artifacts!, processManager: globals.processManager, logger: globals.logger, platform: globals.platform, @@ -76,13 +74,13 @@ class FlutterDevice { /// Create a [FlutterDevice] with optional code generation enabled. static Future create( Device device, { - @required String target, - @required BuildInfo buildInfo, - @required Platform platform, + required String? target, + required BuildInfo buildInfo, + required Platform platform, TargetModel targetModel = TargetModel.flutter, - List experimentalFlags, - ResidentCompiler generator, - String userIdentifier, + List? experimentalFlags, + ResidentCompiler? generator, + String? userIdentifier, }) async { ResidentCompiler generator; final TargetPlatform targetPlatform = await device.targetPlatform; @@ -97,8 +95,8 @@ class FlutterDevice { // used to file a bug, but the compiler will still start up correctly. if (targetPlatform == TargetPlatform.web_javascript) { // TODO(zanderso): consistently provide these flags across platforms. - HostArtifact platformDillArtifact; - final List extraFrontEndOptions = List.of(buildInfo.extraFrontEndOptions ?? []); + late HostArtifact platformDillArtifact; + final List extraFrontEndOptions = List.of(buildInfo.extraFrontEndOptions); if (buildInfo.nullSafetyMode == NullSafetyMode.unsound) { platformDillArtifact = HostArtifact.webPlatformKernelDill; if (!extraFrontEndOptions.contains('--no-sound-null-safety')) { @@ -114,10 +112,10 @@ class FlutterDevice { } generator = ResidentCompiler( - globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk).path, + globals.artifacts!.getHostArtifact(HostArtifact.flutterWebSdk).path, buildMode: buildInfo.mode, trackWidgetCreation: buildInfo.trackWidgetCreation, - fileSystemRoots: buildInfo.fileSystemRoots ?? [], + fileSystemRoots: buildInfo.fileSystemRoots, // Override the filesystem scheme so that the frontend_server can find // the generated entrypoint code. fileSystemScheme: 'org-dartlang-app', @@ -129,14 +127,14 @@ class FlutterDevice { assumeInitializeFromDillUpToDate: buildInfo.assumeInitializeFromDillUpToDate, targetModel: TargetModel.dartdevc, extraFrontEndOptions: extraFrontEndOptions, - platformDill: globals.fs.file(globals.artifacts + platformDill: globals.fs.file(globals.artifacts! .getHostArtifact(platformDillArtifact)) .absolute.uri.toString(), dartDefines: buildInfo.dartDefines, - librariesSpec: globals.fs.file(globals.artifacts + librariesSpec: globals.fs.file(globals.artifacts! .getHostArtifact(HostArtifact.flutterWebLibrariesJson)).uri.toString(), packagesPath: buildInfo.packagesPath, - artifacts: globals.artifacts, + artifacts: globals.artifacts!, processManager: globals.processManager, logger: globals.logger, fileSystem: globals.fs, @@ -149,10 +147,10 @@ class FlutterDevice { if (featureFlags.isSingleWidgetReloadEnabled) '--flutter-widget-cache', '--enable-experiment=alternative-invalidation-strategy', - ...?extraFrontEndOptions, + ...extraFrontEndOptions, ]; generator = ResidentCompiler( - globals.artifacts.getArtifactPath( + globals.artifacts!.getArtifactPath( Artifact.flutterPatchedSdkPath, platform: targetPlatform, mode: buildInfo.mode, @@ -171,7 +169,7 @@ class FlutterDevice { ), assumeInitializeFromDillUpToDate: buildInfo.assumeInitializeFromDillUpToDate, packagesPath: buildInfo.packagesPath, - artifacts: globals.artifacts, + artifacts: globals.artifacts!, processManager: globals.processManager, logger: globals.logger, platform: platform, @@ -189,19 +187,20 @@ class FlutterDevice { ); } - final TargetPlatform targetPlatform; - final Device device; - final ResidentCompiler generator; + final TargetPlatform? targetPlatform; + final Device? device; + final ResidentCompiler? generator; final BuildInfo buildInfo; - final String userIdentifier; + final String? userIdentifier; - DevFSWriter devFSWriter; - Stream observatoryUris; - FlutterVmService vmService; - DevFS devFS; - ApplicationPackage package; - StreamSubscription _loggingSubscription; - bool _isListeningForObservatoryUri; + DevFSWriter? devFSWriter; + Stream? observatoryUris; + FlutterVmService? vmService; + DevFS? devFS; + ApplicationPackage? package; + // ignore: cancel_subscriptions + StreamSubscription? _loggingSubscription; + bool? _isListeningForObservatoryUri; /// Whether the stream [observatoryUris] is still open. bool get isWaitingForObservatory => _isListeningForObservatoryUri ?? false; @@ -216,29 +215,29 @@ class FlutterDevice { /// This ensures that the reload process follows the normal orchestration of /// the Flutter Tools and not just the VM internal service. Future connect({ - ReloadSources reloadSources, - Restart restart, - CompileExpression compileExpression, - GetSkSLMethod getSkSLMethod, - PrintStructuredErrorLogMethod printStructuredErrorLogMethod, - int hostVmServicePort, - int ddsPort, + ReloadSources? reloadSources, + Restart? restart, + CompileExpression? compileExpression, + GetSkSLMethod? getSkSLMethod, + PrintStructuredErrorLogMethod? printStructuredErrorLogMethod, + int? hostVmServicePort, + int? ddsPort, bool disableServiceAuthCodes = false, bool cacheStartupProfile = false, bool enableDds = true, - @required bool allowExistingDdsInstance, - bool ipv6 = false, + required bool allowExistingDdsInstance, + bool? ipv6 = false, }) { final Completer completer = Completer(); - StreamSubscription subscription; + late StreamSubscription subscription; bool isWaitingForVm = false; - subscription = observatoryUris.listen((Uri observatoryUri) async { + subscription = observatoryUris!.listen((Uri? observatoryUri) async { // FYI, this message is used as a sentinel in tests. globals.printTrace('Connecting to service protocol: $observatoryUri'); isWaitingForVm = true; bool existingDds = false; - FlutterVmService service; + FlutterVmService? service; if (enableDds) { void handleError(Exception e, StackTrace st) { globals.printTrace('Fail to connect to service protocol: $observatoryUri: $e'); @@ -250,11 +249,11 @@ class FlutterDevice { // this may not be the case when scraping logcat for URIs. If this URI is // from an old application instance, we shouldn't try and start DDS. try { - service = await connectToVmService(observatoryUri, logger: globals.logger); + service = await connectToVmService(observatoryUri!, logger: globals.logger); await service.dispose(); } on Exception catch (exception) { globals.printTrace('Fail to connect to service protocol: $observatoryUri: $exception'); - if (!completer.isCompleted && !_isListeningForObservatoryUri) { + if (!completer.isCompleted && !_isListeningForObservatoryUri!) { completer.completeError('failed to connect to $observatoryUri'); } return; @@ -264,7 +263,7 @@ class FlutterDevice { // (e.g., failure to bind to a port, failure to connect to the VM service, // attaching to a VM service with existing clients, etc.). try { - await device.dds.startDartDevelopmentService( + await device!.dds.startDartDevelopmentService( observatoryUri, hostPort: ddsPort, ipv6: ipv6, @@ -295,7 +294,7 @@ class FlutterDevice { service = await Future.any( >[ connectToVmService( - enableDds ? device.dds.uri : observatoryUri, + enableDds ? (device!.dds.uri ?? observatoryUri!): observatoryUri!, reloadSources: reloadSources, restart: restart, compileExpression: compileExpression, @@ -305,12 +304,12 @@ class FlutterDevice { logger: globals.logger, ), if (!existingDds) - device.dds.done.whenComplete(() => throw Exception('DDS shut down too early')), + device!.dds.done.whenComplete(() => throw Exception('DDS shut down too early')), ] - ) as FlutterVmService; + ) as FlutterVmService?; } on Exception catch (exception) { globals.printTrace('Fail to connect to service protocol: $observatoryUri: $exception'); - if (!completer.isCompleted && !_isListeningForObservatoryUri) { + if (!completer.isCompleted && !_isListeningForObservatoryUri!) { completer.completeError('failed to connect to $observatoryUri'); } return; @@ -321,7 +320,7 @@ class FlutterDevice { globals.printTrace('Successfully connected to service protocol: $observatoryUri'); vmService = service; - (await device.getLogReader(app: package)).connectedVMService = vmService; + (await device!.getLogReader(app: package)).connectedVMService = vmService; completer.complete(); await subscription.cancel(); }, onError: (dynamic error) { @@ -342,30 +341,30 @@ class FlutterDevice { // TODO(zanderso): https://github.com/flutter/flutter/issues/83127 // When updating `flutter attach` to support running without a device, // this will need to be changed to fall back to io exit. - return device.stopApp(package, userIdentifier: userIdentifier); + await device!.stopApp(package, userIdentifier: userIdentifier); } - Future setupDevFS( + Future setupDevFS( String fsName, Directory rootDirectory, ) { // One devFS per device. Shared by all running instances. devFS = DevFS( - vmService, + vmService!, fsName, rootDirectory, osUtils: globals.os, fileSystem: globals.fs, logger: globals.logger, ); - return devFS.create(); + return devFS!.create(); } Future startEchoingDeviceLog() async { if (_loggingSubscription != null) { return; } - final Stream logStream = (await device.getLogReader(app: package)).logLines; + final Stream logStream = (await device!.getLogReader(app: package)).logLines; if (logStream == null) { globals.printError('Failed to read device log stream'); return; @@ -381,29 +380,29 @@ class FlutterDevice { if (_loggingSubscription == null) { return; } - await _loggingSubscription.cancel(); + await _loggingSubscription!.cancel(); _loggingSubscription = null; } Future initLogReader() async { - final vm_service.VM vm = await vmService.service.getVM(); - final DeviceLogReader logReader = await device.getLogReader(app: package); + final vm_service.VM vm = await vmService!.service.getVM(); + final DeviceLogReader logReader = await device!.getLogReader(app: package); logReader.appPid = vm.pid; } Future runHot({ - HotRunner hotRunner, - String route, + required HotRunner hotRunner, + String? route, }) async { final bool prebuiltMode = hotRunner.applicationBinary != null; final String modeName = hotRunner.debuggingOptions.buildInfo.friendlyModeName; globals.printStatus( 'Launching ${getDisplayPath(hotRunner.mainPath, globals.fs)} ' - 'on ${device.name} in $modeName mode...', + 'on ${device!.name} in $modeName mode...', ); - final TargetPlatform targetPlatform = await device.targetPlatform; - package = await ApplicationPackageFactory.instance.getPackageForPlatform( + final TargetPlatform targetPlatform = await device!.targetPlatform; + package = await ApplicationPackageFactory.instance!.getPackageForPlatform( targetPlatform, buildInfo: hotRunner.debuggingOptions.buildInfo, applicationBinary: hotRunner.applicationBinary, @@ -411,14 +410,14 @@ class FlutterDevice { if (package == null) { String message = 'No application found for $targetPlatform.'; - final String hint = await getMissingPackageHintForPlatform(targetPlatform); + final String? hint = await getMissingPackageHintForPlatform(targetPlatform); if (hint != null) { message += '\n$hint'; } globals.printError(message); return 1; } - devFSWriter = device.createDevFSWriter(package, userIdentifier); + devFSWriter = device!.createDevFSWriter(package, userIdentifier); final Map platformArgs = { 'multidex': hotRunner.multidexEnabled, @@ -427,26 +426,26 @@ class FlutterDevice { await startEchoingDeviceLog(); // Start the application. - final Future futureResult = device.startApp( + final Future futureResult = device!.startApp( package, mainPath: hotRunner.mainPath, debuggingOptions: hotRunner.debuggingOptions, platformArgs: platformArgs, route: route, prebuiltApplication: prebuiltMode, - ipv6: hotRunner.ipv6, + ipv6: hotRunner.ipv6!, userIdentifier: userIdentifier, ); final LaunchResult result = await futureResult; if (!result.started) { - globals.printError('Error launching application on ${device.name}.'); + globals.printError('Error launching application on ${device!.name}.'); await stopEchoingDeviceLog(); return 2; } if (result.hasObservatory) { - observatoryUris = Stream + observatoryUris = Stream .value(result.observatoryUri) .asBroadcastStream(); } else { @@ -458,35 +457,35 @@ class FlutterDevice { } Future runCold({ - ColdRunner coldRunner, - String route, + required ColdRunner coldRunner, + String? route, }) async { - final TargetPlatform targetPlatform = await device.targetPlatform; - package = await ApplicationPackageFactory.instance.getPackageForPlatform( + final TargetPlatform targetPlatform = await device!.targetPlatform; + package = await ApplicationPackageFactory.instance!.getPackageForPlatform( targetPlatform, buildInfo: coldRunner.debuggingOptions.buildInfo, applicationBinary: coldRunner.applicationBinary, ); - devFSWriter = device.createDevFSWriter(package, userIdentifier); + devFSWriter = device!.createDevFSWriter(package, userIdentifier); final String modeName = coldRunner.debuggingOptions.buildInfo.friendlyModeName; final bool prebuiltMode = coldRunner.applicationBinary != null; if (coldRunner.mainPath == null) { assert(prebuiltMode); globals.printStatus( - 'Launching ${package.displayName} ' - 'on ${device.name} in $modeName mode...', + 'Launching ${package!.displayName} ' + 'on ${device!.name} in $modeName mode...', ); } else { globals.printStatus( 'Launching ${getDisplayPath(coldRunner.mainPath, globals.fs)} ' - 'on ${device.name} in $modeName mode...', + 'on ${device!.name} in $modeName mode...', ); } if (package == null) { String message = 'No application found for $targetPlatform.'; - final String hint = await getMissingPackageHintForPlatform(targetPlatform); + final String? hint = await getMissingPackageHintForPlatform(targetPlatform); if (hint != null) { message += '\n$hint'; } @@ -502,24 +501,24 @@ class FlutterDevice { await startEchoingDeviceLog(); - final LaunchResult result = await device.startApp( + final LaunchResult result = await device!.startApp( package, mainPath: coldRunner.mainPath, debuggingOptions: coldRunner.debuggingOptions, platformArgs: platformArgs, route: route, prebuiltApplication: prebuiltMode, - ipv6: coldRunner.ipv6, + ipv6: coldRunner.ipv6!, userIdentifier: userIdentifier, ); if (!result.started) { - globals.printError('Error running application on ${device.name}.'); + globals.printError('Error running application on ${device!.name}.'); await stopEchoingDeviceLog(); return 2; } if (result.hasObservatory) { - observatoryUris = Stream + observatoryUris = Stream .value(result.observatoryUri) .asBroadcastStream(); } else { @@ -531,31 +530,31 @@ class FlutterDevice { } Future updateDevFS({ - Uri mainUri, - String target, - AssetBundle bundle, - DateTime firstBuildTime, + required Uri mainUri, + String? target, + AssetBundle? bundle, + DateTime? firstBuildTime, bool bundleFirstUpload = false, bool bundleDirty = false, bool fullRestart = false, - String projectRootPath, - String pathToReload, - @required String dillOutputPath, - @required List invalidatedFiles, - @required PackageConfig packageConfig, + String? projectRootPath, + required String pathToReload, + required String dillOutputPath, + required List invalidatedFiles, + required PackageConfig packageConfig, }) async { final Status devFSStatus = globals.logger.startProgress( - 'Syncing files to device ${device.name}...', + 'Syncing files to device ${device!.name}...', ); UpdateFSReport report; try { - report = await devFS.update( + report = await devFS!.update( mainUri: mainUri, target: target, bundle: bundle, firstBuildTime: firstBuildTime, bundleFirstUpload: bundleFirstUpload, - generator: generator, + generator: generator!, fullRestart: fullRestart, dillOutputPath: dillOutputPath, trackWidgetCreation: buildInfo.trackWidgetCreation, @@ -585,7 +584,7 @@ class FlutterDevice { /// A subset of the [ResidentRunner] for delegating to attached flutter devices. abstract class ResidentHandlers { - List get flutterDevices; + List get flutterDevices; /// Whether the resident runner has hot reload and restart enabled. bool get hotMode; @@ -619,23 +618,23 @@ abstract class ResidentHandlers { /// Whether all of the connected devices support hot reload. bool get canHotReload; - ResidentDevtoolsHandler get residentDevtoolsHandler; + ResidentDevtoolsHandler? get residentDevtoolsHandler; @protected - Logger get logger; + Logger? get logger; @protected - FileSystem get fileSystem; + FileSystem? get fileSystem; /// Called to print help to the terminal. - void printHelp({ @required bool details }); + void printHelp({ required bool details }); /// Perform a hot reload or hot restart of all attached applications. /// /// If [fullRestart] is true, a hot restart is performed. Otherwise a hot reload /// is run instead. On web devices, this only performs a hot restart regardless of /// the value of [fullRestart]. - Future restart({ bool fullRestart = false, bool pause = false, String reason }) { + Future restart({ bool fullRestart = false, bool pause = false, String? reason }) { final String mode = isRunningProfile ? 'profile' :isRunningRelease ? 'release' : 'this'; throw Exception('${fullRestart ? 'Restart' : 'Reload'} is not supported in $mode mode'); } @@ -645,13 +644,13 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - final String data = await device.vmService.flutterDebugDumpApp( - isolateId: view.uiIsolate.id, + final String data = await device.vmService!.flutterDebugDumpApp( + isolateId: view.uiIsolate!.id!, ); - logger.printStatus(data); + logger!.printStatus(data); } } return true; @@ -662,13 +661,13 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - final String data = await device.vmService.flutterDebugDumpRenderTree( - isolateId: view.uiIsolate.id, + final String data = await device.vmService!.flutterDebugDumpRenderTree( + isolateId: view.uiIsolate!.id!, ); - logger.printStatus(data); + logger!.printStatus(data); } } return true; @@ -685,13 +684,13 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - final Map rasterData = - await device.vmService.renderFrameWithRasterStats( + final Map? rasterData = + await device.vmService!.renderFrameWithRasterStats( viewId: view.id, - uiIsolateId: view.uiIsolate.id, + uiIsolateId: view.uiIsolate!.id, ); if (rasterData != null) { final File tempFile = globals.fsUtils.getUniqueFile( @@ -700,9 +699,9 @@ abstract class ResidentHandlers { 'json', ); tempFile.writeAsStringSync(jsonEncode(rasterData), flush: true); - logger.printStatus('Wrote jank metrics to ${tempFile.absolute.path}'); + logger!.printStatus('Wrote jank metrics to ${tempFile.absolute.path}'); } else { - logger.printWarning('Unable to get jank metrics.'); + logger!.printWarning('Unable to get jank metrics.'); } } } @@ -714,13 +713,13 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol || !isRunningDebug) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - final String data = await device.vmService.flutterDebugDumpLayerTree( - isolateId: view.uiIsolate.id, + final String data = await device.vmService!.flutterDebugDumpLayerTree( + isolateId: view.uiIsolate!.id!, ); - logger.printStatus(data); + logger!.printStatus(data); } } return true; @@ -733,13 +732,13 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - final String data = await device.vmService.flutterDebugDumpSemanticsTreeInTraversalOrder( - isolateId: view.uiIsolate.id, + final String data = await device.vmService!.flutterDebugDumpSemanticsTreeInTraversalOrder( + isolateId: view.uiIsolate!.id!, ); - logger.printStatus(data); + logger!.printStatus(data); } } return true; @@ -752,13 +751,13 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - final String data = await device.vmService.flutterDebugDumpSemanticsTreeInInverseHitTestOrder( - isolateId: view.uiIsolate.id, + final String data = await device.vmService!.flutterDebugDumpSemanticsTreeInInverseHitTestOrder( + isolateId: view.uiIsolate!.id!, ); - logger.printStatus(data); + logger!.printStatus(data); } } return true; @@ -769,11 +768,11 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol || !isRunningDebug) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - await device.vmService.flutterToggleDebugPaintSizeEnabled( - isolateId: view.uiIsolate.id, + await device.vmService!.flutterToggleDebugPaintSizeEnabled( + isolateId: view.uiIsolate!.id!, ); } } @@ -787,14 +786,14 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - for (final FlutterDevice device in flutterDevices) { - if (device.targetPlatform == TargetPlatform.web_javascript) { + for (final FlutterDevice? device in flutterDevices) { + if (device!.targetPlatform == TargetPlatform.web_javascript) { continue; } - final List views = await device.vmService.getFlutterViews(); + final List views = await device.vmService!.getFlutterViews(); for (final FlutterView view in views) { - await device.vmService.flutterTogglePerformanceOverlayOverride( - isolateId: view.uiIsolate.id, + await device.vmService!.flutterTogglePerformanceOverlayOverride( + isolateId: view.uiIsolate!.id!, ); } } @@ -806,11 +805,11 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - await device.vmService.flutterToggleWidgetInspector( - isolateId: view.uiIsolate.id, + await device.vmService!.flutterToggleWidgetInspector( + isolateId: view.uiIsolate!.id!, ); } } @@ -822,11 +821,11 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol || !isRunningDebug) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - await device.vmService.flutterToggleInvertOversizedImages( - isolateId: view.uiIsolate.id, + await device.vmService!.flutterToggleInvertOversizedImages( + isolateId: view.uiIsolate!.id!, ); } } @@ -838,11 +837,11 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - await device.vmService.flutterToggleProfileWidgetBuilds( - isolateId: view.uiIsolate.id, + await device.vmService!.flutterToggleProfileWidgetBuilds( + isolateId: view.uiIsolate!.id!, ); } } @@ -854,9 +853,9 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol) { return false; } - final List views = await flutterDevices.first.vmService.getFlutterViews(); - final Brightness current = await flutterDevices.first.vmService.flutterBrightnessOverride( - isolateId: views.first.uiIsolate.id, + final List views = await flutterDevices.first!.vmService!.getFlutterViews(); + final Brightness? current = await flutterDevices.first!.vmService!.flutterBrightnessOverride( + isolateId: views.first.uiIsolate!.id!, ); Brightness next; if (current == Brightness.light) { @@ -864,15 +863,15 @@ abstract class ResidentHandlers { } else { next = Brightness.light; } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - await device.vmService.flutterBrightnessOverride( - isolateId: view.uiIsolate.id, + await device.vmService!.flutterBrightnessOverride( + isolateId: view.uiIsolate!.id!, brightness: next, ); } - logger.printStatus('Changed brightness to $next.'); + logger!.printStatus('Changed brightness to $next.'); } return true; } @@ -882,39 +881,39 @@ abstract class ResidentHandlers { if (!supportsServiceProtocol || !isRunningDebug) { return false; } - final List views = await flutterDevices.first.vmService.getFlutterViews(); + final List views = await flutterDevices.first!.vmService!.getFlutterViews(); final String from = await flutterDevices - .first.vmService.flutterPlatformOverride( - isolateId: views.first.uiIsolate.id, + .first!.vmService!.flutterPlatformOverride( + isolateId: views.first.uiIsolate!.id!, ); final String to = nextPlatform(from); - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - await device.vmService.flutterPlatformOverride( + await device.vmService!.flutterPlatformOverride( platform: to, - isolateId: view.uiIsolate.id, + isolateId: view.uiIsolate!.id!, ); } } - logger.printStatus('Switched operating system to $to'); + logger!.printStatus('Switched operating system to $to'); return true; } /// Write the SkSL shaders to a zip file in build directory. /// /// Returns the name of the file, or `null` on failures. - Future writeSkSL() async { + Future writeSkSL() async { if (!supportsWriteSkSL) { throw Exception('writeSkSL is not supported by this runner.'); } final List views = await flutterDevices - .first - .vmService.getFlutterViews(); - final Map data = await flutterDevices.first.vmService.getSkSLs( + .first! + .vmService!.getFlutterViews(); + final Map data = await (flutterDevices.first!.vmService!.getSkSLs( viewId: views.first.id, - ); - final Device device = flutterDevices.first.device; + ) as FutureOr>); + final Device device = flutterDevices.first!.device!; return sharedSkSlWriter(device, data); } @@ -932,22 +931,22 @@ abstract class ResidentHandlers { /// if an error occurs after the data has already been received, such as /// from restoring the debug banner. Future screenshot(FlutterDevice device) async { - if (!device.device.supportsScreenshot && !supportsServiceProtocol) { + if (!device.device!.supportsScreenshot && !supportsServiceProtocol) { return; } - final Status status = logger.startProgress( - 'Taking screenshot for ${device.device.name}...', + final Status status = logger!.startProgress( + 'Taking screenshot for ${device.device!.name}...', ); final File outputFile = getUniqueFile( - fileSystem.currentDirectory, + fileSystem!.currentDirectory, 'flutter', 'png', ); try { bool result; - if (device.device.supportsScreenshot) { - result = await _toggleDebugBanner(device, () => device.device.takeScreenshot(outputFile)); + if (device.device!.supportsScreenshot) { + result = await _toggleDebugBanner(device, () => device.device!.takeScreenshot(outputFile)); } else { result = await _takeVmServiceScreenshot(device, outputFile); } @@ -956,12 +955,12 @@ abstract class ResidentHandlers { } final int sizeKB = outputFile.lengthSync() ~/ 1024; status.stop(); - logger.printStatus( - 'Screenshot written to ${fileSystem.path.relative(outputFile.path)} (${sizeKB}kB).', + logger!.printStatus( + 'Screenshot written to ${fileSystem!.path.relative(outputFile.path)} (${sizeKB}kB).', ); } on Exception catch (error) { status.cancel(); - logger.printError('Error taking screenshot: $error'); + logger!.printError('Error taking screenshot: $error'); } } @@ -970,13 +969,13 @@ abstract class ResidentHandlers { assert(supportsServiceProtocol); return _toggleDebugBanner(device, () async { - final vm_service.Response response = isWebDevice - ? await device.vmService.callMethodWrapper('ext.dwds.screenshot') - : await device.vmService.screenshot(); + final vm_service.Response? response = isWebDevice + ? await device.vmService!.callMethodWrapper('ext.dwds.screenshot') + : await device.vmService!.screenshot(); if (response == null) { throw Exception('Failed to take screenshot'); } - final String data = response.json[isWebDevice ? 'data' : 'screenshot'] as String; + final String data = response.json![isWebDevice ? 'data' : 'screenshot'] as String; outputFile.writeAsBytesSync(base64.decode(data)); }); } @@ -984,20 +983,20 @@ abstract class ResidentHandlers { Future _toggleDebugBanner(FlutterDevice device, Future Function() cb) async { List views = []; if (supportsServiceProtocol) { - views = await device.vmService.getFlutterViews(); + views = await device.vmService!.getFlutterViews(); } Future setDebugBanner(bool value) async { try { for (final FlutterView view in views) { - await device.vmService.flutterDebugAllowBanner( + await device.vmService!.flutterDebugAllowBanner( value, - isolateId: view.uiIsolate.id, + isolateId: view.uiIsolate!.id!, ); } return true; } on vm_service.RPCError catch (error) { - logger.printError('Error communicating with Flutter on the device: $error'); + logger!.printError('Error communicating with Flutter on the device: $error'); return false; } } @@ -1039,13 +1038,13 @@ abstract class ResidentHandlers { abstract class ResidentRunner extends ResidentHandlers { ResidentRunner( this.flutterDevices, { - @required this.target, - @required this.debuggingOptions, - String projectRootPath, + required this.target, + required this.debuggingOptions, + String? projectRootPath, this.ipv6, this.stayResident = true, this.hotMode = true, - String dillOutputPath, + String? dillOutputPath, this.machine = false, ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler, }) : mainPath = globals.fs.file(target).absolute.path, @@ -1069,21 +1068,21 @@ abstract class ResidentRunner extends ResidentHandlers { } @override - Logger get logger => globals.logger; + Logger? get logger => globals.logger; @override - FileSystem get fileSystem => globals.fs; + FileSystem? get fileSystem => globals.fs; @override - final List flutterDevices; + final List flutterDevices; final String target; final DebuggingOptions debuggingOptions; @override final bool stayResident; - final bool ipv6; - final String _dillOutputPath; + final bool? ipv6; + final String? _dillOutputPath; /// The parent location of the incremental artifacts. final Directory artifactDirectory; final String packagesFilePath; @@ -1095,28 +1094,28 @@ abstract class ResidentRunner extends ResidentHandlers { final bool machine; @override - ResidentDevtoolsHandler get residentDevtoolsHandler => _residentDevtoolsHandler; - ResidentDevtoolsHandler _residentDevtoolsHandler; + ResidentDevtoolsHandler? get residentDevtoolsHandler => _residentDevtoolsHandler; + ResidentDevtoolsHandler? _residentDevtoolsHandler; bool _exited = false; Completer _finished = Completer(); - BuildResult _lastBuild; - Environment _environment; + BuildResult? _lastBuild; + Environment? _environment; @override bool hotMode; /// Returns true if every device is streaming observatory URIs. bool get isWaitingForObservatory { - return flutterDevices.every((FlutterDevice device) { - return device.isWaitingForObservatory; + return flutterDevices.every((FlutterDevice? device) { + return device!.isWaitingForObservatory; }); } String get dillOutputPath => _dillOutputPath ?? globals.fs.path.join(artifactDirectory.path, 'app.dill'); String getReloadPath({ bool fullRestart = false, - @required bool swap, + required bool swap, }) { if (!fullRestart) { return 'main.dart.incremental.dill'; @@ -1152,15 +1151,15 @@ abstract class ResidentRunner extends ResidentHandlers { // // Would be null if there is no device connected or // there is no devFS associated with the first device. - Uri get uri => flutterDevices.first?.devFS?.baseUri; + Uri? get uri => flutterDevices.first?.devFS?.baseUri; /// Returns [true] if the resident runner exited after invoking [exit()]. bool get exited => _exited; @override bool get supportsRestart { - return isRunningDebug && flutterDevices.every((FlutterDevice device) { - return device.device.supportsHotRestart; + return isRunningDebug && flutterDevices.every((FlutterDevice? device) { + return device!.device!.supportsHotRestart; }); } @@ -1171,20 +1170,20 @@ abstract class ResidentRunner extends ResidentHandlers { /// /// Returns the exit code that we should use for the flutter tool process; 0 /// for success, 1 for user error (e.g. bad arguments), 2 for other failures. - Future run({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Future run({ + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, bool enableDevTools = false, - String route, + String? route, }); /// Connect to a flutter application. /// /// [needsFullRestart] defaults to `true`, and controls if the frontend server should /// compile a full dill. This should be set to `false` if this is called in [ResidentRunner.run], since that method already perfoms an initial compilation. - Future attach({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Future attach({ + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, bool allowExistingDdsInstance = false, bool enableDevTools = false, bool needsFullRestart = true, @@ -1193,7 +1192,7 @@ abstract class ResidentRunner extends ResidentHandlers { @override Future runSourceGenerators() async { _environment ??= Environment( - artifacts: globals.artifacts, + artifacts: globals.artifacts!, logger: globals.logger, cacheDir: globals.cache.getRoot(), engineVersion: globals.flutterVersion.engineRevision, @@ -1217,11 +1216,11 @@ abstract class ResidentRunner extends ResidentHandlers { _lastBuild = await globals.buildSystem.buildIncremental( compositeTarget, - _environment, + _environment!, _lastBuild, ); - if (!_lastBuild.success) { - for (final ExceptionMeasurement exceptionMeasurement in _lastBuild.exceptions.values) { + if (!_lastBuild!.success) { + for (final ExceptionMeasurement exceptionMeasurement in _lastBuild!.exceptions.values) { globals.printError( exceptionMeasurement.exception.toString(), stackTrace: globals.logger.isVerbose @@ -1237,7 +1236,7 @@ abstract class ResidentRunner extends ResidentHandlers { void writeVmServiceFile() { if (debuggingOptions.vmserviceOutFile != null) { try { - final String address = flutterDevices.first.vmService.wsAddress.toString(); + final String address = flutterDevices.first!.vmService!.wsAddress.toString(); final File vmserviceOutFile = globals.fs.file(debuggingOptions.vmserviceOutFile); vmserviceOutFile.createSync(recursive: true); vmserviceOutFile.writeAsStringSync(address); @@ -1250,7 +1249,7 @@ abstract class ResidentRunner extends ResidentHandlers { @override Future exit() async { _exited = true; - await residentDevtoolsHandler.shutdown(); + await residentDevtoolsHandler!.shutdown(); await stopEchoingDeviceLog(); await preExit(); await exitApp(); // calls appFinished @@ -1259,7 +1258,7 @@ abstract class ResidentRunner extends ResidentHandlers { @override Future detach() async { - await residentDevtoolsHandler.shutdown(); + await residentDevtoolsHandler!.shutdown(); await stopEchoingDeviceLog(); await preExit(); await shutdownDartDevelopmentService(); @@ -1268,15 +1267,15 @@ abstract class ResidentRunner extends ResidentHandlers { Future stopEchoingDeviceLog() async { await Future.wait( - flutterDevices.map>((FlutterDevice device) => device.stopEchoingDeviceLog()) + flutterDevices.map>((FlutterDevice? device) => device!.stopEchoingDeviceLog()) ); } Future shutdownDartDevelopmentService() async { await Future.wait( flutterDevices.map>( - (FlutterDevice device) => device.device?.dds?.shutdown() - ).where((Future element) => element != null) + (FlutterDevice? device) => device?.device?.dds.shutdown() ?? Future.value() + ) ); } @@ -1303,7 +1302,7 @@ abstract class ResidentRunner extends ResidentHandlers { void printStructuredErrorLog(vm_service.Event event) { if (event.extensionKind == 'Flutter.Error' && !machine) { - final Map json = event.extensionData?.data; + final Map? json = event.extensionData?.data; if (json != null && json.containsKey('renderedErrorText')) { globals.printStatus('\n${json['renderedErrorText']}'); } @@ -1317,19 +1316,19 @@ abstract class ResidentRunner extends ResidentHandlers { // a string as the error object, which will be used by the caller (attach()) // to display an error message. Future connectToServiceProtocol({ - ReloadSources reloadSources, - Restart restart, - CompileExpression compileExpression, - GetSkSLMethod getSkSLMethod, - @required bool allowExistingDdsInstance, + ReloadSources? reloadSources, + Restart? restart, + CompileExpression? compileExpression, + GetSkSLMethod? getSkSLMethod, + required bool allowExistingDdsInstance, }) async { if (!debuggingOptions.debuggingEnabled) { throw Exception('The service protocol is not enabled.'); } _finished = Completer(); // Listen for service protocol connection to close. - for (final FlutterDevice device in flutterDevices) { - await device.connect( + for (final FlutterDevice? device in flutterDevices) { + await device!.connect( reloadSources: reloadSources, restart: restart, compileExpression: compileExpression, @@ -1343,12 +1342,12 @@ abstract class ResidentRunner extends ResidentHandlers { disableServiceAuthCodes: debuggingOptions.disableServiceAuthCodes, cacheStartupProfile: debuggingOptions.cacheStartupProfile, ); - await device.vmService.getFlutterViews(); + await device.vmService!.getFlutterViews(); // This hooks up callbacks for when the connection stops in the future. // We don't want to wait for them. We don't handle errors in those callbacks' // futures either because they just print to logger and is not critical. - unawaited(device.vmService.service.onDone.then( + unawaited(device.vmService!.service.onDone.then( _serviceProtocolDone, onError: _serviceProtocolError, ).whenComplete(_serviceDisconnected)); @@ -1359,7 +1358,7 @@ abstract class ResidentRunner extends ResidentHandlers { globals.printTrace('Service protocol connection closed.'); } - Future _serviceProtocolError(dynamic error, StackTrace stack) { + Future _serviceProtocolError(Object error, StackTrace stack) { globals.printTrace('Service protocol connection closed with an error: $error\n$stack'); return Future.error(error, stack); } @@ -1408,7 +1407,7 @@ abstract class ResidentRunner extends ResidentHandlers { Future exitApp() async { final List> futures = >[ - for (final FlutterDevice device in flutterDevices) device.exitApps(), + for (final FlutterDevice? device in flutterDevices) device!.exitApps(), ]; await Future.wait(futures); appFinished(); @@ -1418,30 +1417,30 @@ abstract class ResidentRunner extends ResidentHandlers { bool _reportedDebuggers = false; void printDebuggerList({ bool includeObservatory = true, bool includeDevtools = true }) { - final DevToolsServerAddress devToolsServerAddress = residentDevtoolsHandler.activeDevToolsServer; - if (!residentDevtoolsHandler.readyToAnnounce) { + final DevToolsServerAddress? devToolsServerAddress = residentDevtoolsHandler!.activeDevToolsServer; + if (!residentDevtoolsHandler!.readyToAnnounce) { includeDevtools = false; } assert(!includeDevtools || devToolsServerAddress != null); - for (final FlutterDevice device in flutterDevices) { - if (device.vmService == null) { + for (final FlutterDevice? device in flutterDevices) { + if (device!.vmService == null) { continue; } if (includeObservatory) { // Caution: This log line is parsed by device lab tests. globals.printStatus( - 'An Observatory debugger and profiler on ${device.device.name} is available at: ' - '${device.vmService.httpAddress}', + 'An Observatory debugger and profiler on ${device.device!.name} is available at: ' + '${device.vmService!.httpAddress}', ); } if (includeDevtools) { - final Uri uri = devToolsServerAddress.uri?.replace( - queryParameters: {'uri': '${device.vmService.httpAddress}'}, + final Uri? uri = devToolsServerAddress!.uri?.replace( + queryParameters: {'uri': '${device.vmService!.httpAddress}'}, ); if (uri != null) { globals.printStatus( 'The Flutter DevTools debugger and profiler ' - 'on ${device.device.name} is available at: ${urlToDisplayString(uri)}', + 'on ${device.device!.name} is available at: ${urlToDisplayString(uri)}', ); } } @@ -1451,7 +1450,7 @@ abstract class ResidentRunner extends ResidentHandlers { void printHelpDetails() { commandHelp.v.print(); - if (flutterDevices.any((FlutterDevice d) => d.device.supportsScreenshot)) { + if (flutterDevices.any((FlutterDevice? d) => d!.device!.supportsScreenshot)) { commandHelp.s.print(); } if (supportsServiceProtocol) { @@ -1505,7 +1504,7 @@ class OperationResult { /// Whether this error should cause the runner to exit. final bool fatal; - final UpdateFSReport updateFSReport; + final UpdateFSReport? updateFSReport; bool get isOk => code == 0; @@ -1522,7 +1521,7 @@ class OperationResultExtraTiming { final int timeInMs; } -Future getMissingPackageHintForPlatform(TargetPlatform platform) async { +Future getMissingPackageHintForPlatform(TargetPlatform platform) async { switch (platform) { case TargetPlatform.android_arm: case TargetPlatform.android_arm64: @@ -1544,18 +1543,17 @@ Future getMissingPackageHintForPlatform(TargetPlatform platform) async { case TargetPlatform.windows_x64: return null; } - return null; // dead code, remove after null safety migration } /// Redirects terminal commands to the correct resident runner methods. class TerminalHandler { TerminalHandler(this.residentRunner, { - @required Logger logger, - @required Terminal terminal, - @required Signals signals, - @required io.ProcessInfo processInfo, - @required bool reportReady, - String pidFile, + required Logger logger, + required Terminal terminal, + required Signals signals, + required io.ProcessInfo processInfo, + required bool reportReady, + String? pidFile, }) : _logger = logger, _terminal = terminal, _signals = signals, @@ -1568,15 +1566,15 @@ class TerminalHandler { final Signals _signals; final io.ProcessInfo _processInfo; final bool _reportReady; - final String _pidFile; + final String? _pidFile; final ResidentHandlers residentRunner; bool _processingUserRequest = false; - StreamSubscription subscription; - File _actualPidFile; + StreamSubscription? subscription; + File? _actualPidFile; @visibleForTesting - String lastReceivedCommand; + String? lastReceivedCommand; /// This is only a buffer logger in unit tests @visibleForTesting @@ -1606,7 +1604,7 @@ class TerminalHandler { _addSignalHandler(io.ProcessSignal.sigusr2, _handleSignal); if (_pidFile != null) { _logger.printTrace('Writing pid to: $_pidFile'); - _actualPidFile = _processInfo.writePidFile(_pidFile); + _actualPidFile = _processInfo.writePidFile(_pidFile!); } } } @@ -1616,10 +1614,10 @@ class TerminalHandler { assert(residentRunner.stayResident); if (_actualPidFile != null) { try { - _logger.printTrace('Deleting pid file (${_actualPidFile.path}).'); - _actualPidFile.deleteSync(); + _logger.printTrace('Deleting pid file (${_actualPidFile!.path}).'); + _actualPidFile!.deleteSync(); } on FileSystemException catch (error) { - _logger.printWarning('Failed to delete pid file (${_actualPidFile.path}): ${error.message}'); + _logger.printWarning('Failed to delete pid file (${_actualPidFile!.path}): ${error.message}'); } _actualPidFile = null; } @@ -1627,7 +1625,7 @@ class TerminalHandler { _signals.removeHandler(entry.key, entry.value); } _signalTokens.clear(); - subscription.cancel(); + subscription?.cancel(); } /// Returns [true] if the input has been handled by this function. @@ -1707,8 +1705,8 @@ class TerminalHandler { } return true; case 's': - for (final FlutterDevice device in residentRunner.flutterDevices) { - await residentRunner.screenshot(device); + for (final FlutterDevice? device in residentRunner.flutterDevices) { + await residentRunner.screenshot(device!); } return true; case 'S': @@ -1720,7 +1718,7 @@ class TerminalHandler { return residentRunner.debugDumpSemanticsTreeInInverseHitTestOrder(); case 'v': case 'V': - return residentRunner.residentDevtoolsHandler.launchDevToolsInBrowser(flutterDevices: residentRunner.flutterDevices); + return residentRunner.residentDevtoolsHandler!.launchDevToolsInBrowser(flutterDevices: residentRunner.flutterDevices); case 'w': case 'W': return residentRunner.debugDumpApp(); @@ -1771,7 +1769,7 @@ class TerminalHandler { } } - Future _cleanUp(io.ProcessSignal signal) async { + Future _cleanUp(io.ProcessSignal? signal) async { _terminal.singleCharMode = false; await subscription?.cancel(); await residentRunner.cleanupAfterSignal(); @@ -1781,9 +1779,9 @@ class TerminalHandler { class DebugConnectionInfo { DebugConnectionInfo({ this.httpUri, this.wsUri, this.baseUri }); - final Uri httpUri; - final Uri wsUri; - final String baseUri; + final Uri? httpUri; + final Uri? wsUri; + final String? baseUri; } /// Returns the next platform value for the switcher. @@ -1808,13 +1806,13 @@ String nextPlatform(String currentPlatform) { /// A launcher for the devtools debugger and analysis tool. abstract class DevtoolsLauncher { - static DevtoolsLauncher get instance => context.get(); + static DevtoolsLauncher? get instance => context.get(); /// Serve Dart DevTools and return the host and port they are available on. /// /// This method must return a future that is guaranteed not to fail, because it /// will be used in unawaited contexts. It may, however, return null. - Future serve(); + Future serve(); /// Launch a Dart DevTools process, optionally targeting a specific VM Service /// URI if [vmServiceUri] is non-null. @@ -1824,7 +1822,7 @@ abstract class DevtoolsLauncher { /// /// This method must return a future that is guaranteed not to fail, because it /// will be used in unawaited contexts. - Future launch(Uri vmServiceUri, {List additionalArguments}); + Future launch(Uri vmServiceUri, {List? additionalArguments}); Future close(); @@ -1832,7 +1830,7 @@ abstract class DevtoolsLauncher { /// will technically never complete. /// /// Us this as an indicator that the process has started. - Future processStart; + Future? processStart; /// Returns a future that completes when the DevTools server is ready. /// @@ -1841,9 +1839,9 @@ abstract class DevtoolsLauncher { Future get ready => _readyCompleter.future; Completer _readyCompleter = Completer(); - Uri get devToolsUrl => _devToolsUrl; - Uri _devToolsUrl; - set devToolsUrl(Uri value) { + Uri? get devToolsUrl => _devToolsUrl; + Uri? _devToolsUrl; + set devToolsUrl(Uri? value) { assert((_devToolsUrl == null) != (value == null)); _devToolsUrl = value; if (_devToolsUrl != null) { @@ -1856,11 +1854,11 @@ abstract class DevtoolsLauncher { /// The URL of the current DevTools server. /// /// Returns null if [ready] is not complete. - DevToolsServerAddress get activeDevToolsServer { + DevToolsServerAddress? get activeDevToolsServer { if (_devToolsUrl == null) { return null; } - return DevToolsServerAddress(devToolsUrl.host, devToolsUrl.port); + return DevToolsServerAddress(devToolsUrl!.host, devToolsUrl!.port); } } @@ -1870,7 +1868,7 @@ class DevToolsServerAddress { final String host; final int port; - Uri get uri { + Uri? get uri { if (host == null || port == null) { return null; } diff --git a/packages/flutter_tools/lib/src/run_cold.dart b/packages/flutter_tools/lib/src/run_cold.dart index ebbcb57ac7e6..8f1ae56e6a7a 100644 --- a/packages/flutter_tools/lib/src/run_cold.dart +++ b/packages/flutter_tools/lib/src/run_cold.dart @@ -2,18 +2,12 @@ // 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 'package:meta/meta.dart'; - import 'base/file_system.dart'; import 'base/logger.dart'; import 'build_info.dart'; -import 'device.dart'; import 'globals.dart' as globals; -import 'resident_devtools_handler.dart'; import 'resident_runner.dart'; import 'tracing.dart'; import 'vmservice.dart'; @@ -21,31 +15,24 @@ import 'vmservice.dart'; const String kFlutterTestOutputsDirEnvName = 'FLUTTER_TEST_OUTPUTS_DIR'; class ColdRunner extends ResidentRunner { ColdRunner( - List devices, { - @required String target, - @required DebuggingOptions debuggingOptions, + super.devices, { + required super.target, + required super.debuggingOptions, this.traceStartup = false, this.awaitFirstFrameWhenTracing = true, this.applicationBinary, this.multidexEnabled = false, - bool ipv6 = false, - bool stayResident = true, - bool machine = false, - ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler, + bool super.ipv6 = false, + super.stayResident, + super.machine, + super.devtoolsHandler, }) : super( - devices, - target: target, - debuggingOptions: debuggingOptions, hotMode: false, - stayResident: stayResident, - ipv6: ipv6, - machine: machine, - devtoolsHandler: devtoolsHandler, ); final bool traceStartup; final bool awaitFirstFrameWhenTracing; - final File applicationBinary; + final File? applicationBinary; final bool multidexEnabled; bool _didAttach = false; @@ -60,14 +47,14 @@ class ColdRunner extends ResidentRunner { @override Future run({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, bool enableDevTools = false, - String route, + String? route, }) async { try { - for (final FlutterDevice device in flutterDevices) { - final int result = await device.runCold( + for (final FlutterDevice? device in flutterDevices) { + final int result = await device!.runCold( coldRunner: this, route: route, ); @@ -95,38 +82,38 @@ class ColdRunner extends ResidentRunner { if (enableDevTools && debuggingEnabled) { // The method below is guaranteed never to return a failing future. - unawaited(residentDevtoolsHandler.serveAndAnnounceDevTools( + unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools( devToolsServerAddress: debuggingOptions.devToolsServerAddress, flutterDevices: flutterDevices, )); } - if (flutterDevices.first.observatoryUris != null) { + if (flutterDevices.first!.observatoryUris != null) { // For now, only support one debugger connection. connectionInfoCompleter?.complete(DebugConnectionInfo( - httpUri: flutterDevices.first.vmService.httpAddress, - wsUri: flutterDevices.first.vmService.wsAddress, + httpUri: flutterDevices.first!.vmService!.httpAddress, + wsUri: flutterDevices.first!.vmService!.wsAddress, )); } globals.printTrace('Application running.'); - for (final FlutterDevice device in flutterDevices) { - if (device.vmService == null) { + for (final FlutterDevice? device in flutterDevices) { + if (device!.vmService == null) { continue; } await device.initLogReader(); - globals.printTrace('Connected to ${device.device.name}'); + globals.printTrace('Connected to ${device.device!.name}'); } if (traceStartup) { // Only trace startup for the first device. - final FlutterDevice device = flutterDevices.first; + final FlutterDevice device = flutterDevices.first!; if (device.vmService != null) { - globals.printStatus('Tracing startup on ${device.device.name}.'); + globals.printStatus('Tracing startup on ${device.device!.name}.'); final String outputPath = globals.platform.environment[kFlutterTestOutputsDirEnvName] ?? getBuildDirectory(); await downloadStartupTrace( - device.vmService, + device.vmService!, awaitFirstFrame: awaitFirstFrameWhenTracing, logger: globals.logger, output: globals.fs.directory(outputPath), @@ -148,8 +135,8 @@ class ColdRunner extends ResidentRunner { @override Future attach({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, bool allowExistingDdsInstance = false, bool enableDevTools = false, bool needsFullRestart = true, @@ -165,11 +152,11 @@ class ColdRunner extends ResidentRunner { return 2; } - for (final FlutterDevice device in flutterDevices) { - await device.initLogReader(); + for (final FlutterDevice? device in flutterDevices) { + await device!.initLogReader(); } - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { globals.printTrace('Connected to $view.'); } @@ -177,7 +164,7 @@ class ColdRunner extends ResidentRunner { if (enableDevTools && debuggingEnabled) { // The method below is guaranteed never to return a failing future. - unawaited(residentDevtoolsHandler.serveAndAnnounceDevTools( + unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools( devToolsServerAddress: debuggingOptions.devToolsServerAddress, flutterDevices: flutterDevices, )); @@ -202,16 +189,16 @@ class ColdRunner extends ResidentRunner { @override Future cleanupAtFinish() async { - for (final FlutterDevice flutterDevice in flutterDevices) { - await flutterDevice.device.dispose(); + for (final FlutterDevice? flutterDevice in flutterDevices) { + await flutterDevice!.device!.dispose(); } - await residentDevtoolsHandler.shutdown(); + await residentDevtoolsHandler!.shutdown(); await stopEchoingDeviceLog(); } @override - void printHelp({ @required bool details }) { + void printHelp({ required bool details }) { globals.printStatus('Flutter run key commands.'); if (details) { printHelpDetails(); @@ -229,10 +216,10 @@ class ColdRunner extends ResidentRunner { @override Future preExit() async { - for (final FlutterDevice device in flutterDevices) { + for (final FlutterDevice? device in flutterDevices) { // If we're running in release mode, stop the app using the device logic. - if (device.vmService == null) { - await device.device.stopApp(device.package, userIdentifier: device.userIdentifier); + if (device!.vmService == null) { + await device.device!.stopApp(device.package, userIdentifier: device.userIdentifier); } } await super.preExit(); diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index e2dfe5147cbb..8629638317ab 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -2,7 +2,7 @@ // 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'; @@ -17,7 +17,6 @@ import 'base/logger.dart'; import 'base/platform.dart'; import 'base/utils.dart'; import 'build_info.dart'; -import 'bundle.dart'; import 'compile.dart'; import 'convert.dart'; import 'dart/package_map.dart'; @@ -27,7 +26,6 @@ import 'features.dart'; import 'globals.dart' as globals; import 'project.dart'; import 'reporting/reporting.dart'; -import 'resident_devtools_handler.dart'; import 'resident_runner.dart'; import 'vmservice.dart'; @@ -37,7 +35,7 @@ ProjectFileInvalidator get projectFileInvalidator => context.get context.get(); +HotRunnerConfig? get hotRunnerConfig => context.get(); class HotRunnerConfig { /// Should the hot runner assume that the minimal Dart dependencies do not change? @@ -48,13 +46,13 @@ class HotRunnerConfig { /// A hook for implementations to perform any necessary initialization prior /// to a hot restart. Should return true if the hot restart should continue. - Future setupHotRestart() async { + Future setupHotRestart() async { return true; } /// A hook for implementations to perform any necessary initialization prior /// to a hot reload. Should return true if the hot restart should continue. - Future setupHotReload() async { + Future setupHotReload() async { return true; } @@ -75,25 +73,25 @@ const bool kHotReloadDefault = true; class DeviceReloadReport { DeviceReloadReport(this.device, this.reports); - FlutterDevice device; + FlutterDevice? device; List reports; // List has one report per Flutter view. } class HotRunner extends ResidentRunner { HotRunner( - List devices, { - @required String target, - @required DebuggingOptions debuggingOptions, + super.devices, { + required super.target, + required super.debuggingOptions, this.benchmarkMode = false, this.applicationBinary, this.hostIsIde = false, - String projectRootPath, - String dillOutputPath, - bool stayResident = true, - bool ipv6 = false, - bool machine = false, + super.projectRootPath, + super.dillOutputPath, + super.stayResident, + bool super.ipv6 = false, + super.machine, this.multidexEnabled = false, - ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler, + super.devtoolsHandler, StopwatchFactory stopwatchFactory = const StopwatchFactory(), ReloadSourcesHelper reloadSourcesHelper = _defaultReloadSourcesHelper, ReassembleHelper reassembleHelper = _defaultReassembleHelper, @@ -101,16 +99,7 @@ class HotRunner extends ResidentRunner { _reloadSourcesHelper = reloadSourcesHelper, _reassembleHelper = reassembleHelper, super( - devices, - target: target, - debuggingOptions: debuggingOptions, - projectRootPath: projectRootPath, - stayResident: stayResident, hotMode: true, - dillOutputPath: dillOutputPath, - ipv6: ipv6, - machine: machine, - devtoolsHandler: devtoolsHandler, ); final StopwatchFactory _stopwatchFactory; @@ -118,7 +107,7 @@ class HotRunner extends ResidentRunner { final ReassembleHelper _reassembleHelper; final bool benchmarkMode; - final File applicationBinary; + final File? applicationBinary; final bool hostIsIde; final bool multidexEnabled; @@ -140,11 +129,11 @@ class HotRunner extends ResidentRunner { final Map> benchmarkData = >{}; - DateTime firstBuildTime; + DateTime? firstBuildTime; - String _targetPlatform; - String _sdkName; - bool _emulator; + String? _targetPlatform; + String? _sdkName; + bool? _emulator; Future _calculateTargetPlatform() async { if (_targetPlatform != null) { @@ -152,7 +141,7 @@ class HotRunner extends ResidentRunner { } if (flutterDevices.length == 1) { - final Device device = flutterDevices.first.device; + final Device device = flutterDevices.first!.device!; _targetPlatform = getNameForTargetPlatform(await device.targetPlatform); _sdkName = await device.sdkNameAndVersion; _emulator = await device.isLocalEmulator; @@ -169,7 +158,7 @@ class HotRunner extends ResidentRunner { void _addBenchmarkData(String name, int value) { benchmarkData[name] ??= []; - benchmarkData[name].add(value); + benchmarkData[name]!.add(value); } Future _reloadSourcesService( @@ -205,16 +194,16 @@ class HotRunner extends ResidentRunner { List definitions, List typeDefinitions, String libraryUri, - String klass, + String? klass, bool isStatic, ) async { - for (final FlutterDevice device in flutterDevices) { - if (device.generator != null) { - final CompilerOutput compilerOutput = - await device.generator.compileExpression(expression, definitions, + for (final FlutterDevice? device in flutterDevices) { + if (device!.generator != null) { + final CompilerOutput? compilerOutput = + await device.generator!.compileExpression(expression, definitions, typeDefinitions, libraryUri, klass, isStatic); if (compilerOutput != null && compilerOutput.expressionData != null) { - return base64.encode(compilerOutput.expressionData); + return base64.encode(compilerOutput.expressionData!); } } } @@ -224,8 +213,8 @@ class HotRunner extends ResidentRunner { // Returns the exit code of the flutter tool process, like [run]. @override Future attach({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, bool allowExistingDdsInstance = false, bool enableDevTools = false, bool needsFullRestart = true, @@ -250,23 +239,23 @@ class HotRunner extends ResidentRunner { if (enableDevTools) { // The method below is guaranteed never to return a failing future. - unawaited(residentDevtoolsHandler.serveAndAnnounceDevTools( + unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools( devToolsServerAddress: debuggingOptions.devToolsServerAddress, flutterDevices: flutterDevices, )); } - for (final FlutterDevice device in flutterDevices) { - await device.initLogReader(); + for (final FlutterDevice? device in flutterDevices) { + await device!.initLogReader(); } try { - final List baseUris = await _initDevFS(); + final List baseUris = await _initDevFS(); if (connectionInfoCompleter != null) { // Only handle one debugger connection. connectionInfoCompleter.complete( DebugConnectionInfo( - httpUri: flutterDevices.first.vmService.httpAddress, - wsUri: flutterDevices.first.vmService.wsAddress, + httpUri: flutterDevices.first!.vmService!.httpAddress, + wsUri: flutterDevices.first!.vmService!.wsAddress, baseUri: baseUris.first.toString(), ), ); @@ -286,13 +275,13 @@ class HotRunner extends ResidentRunner { return 3; } - for (final FlutterDevice device in flutterDevices) { + for (final FlutterDevice? device in flutterDevices) { // VM must have accepted the kernel binary, there will be no reload // report, so we let incremental compiler know that source code was accepted. - if (device.generator != null) { - device.generator.accept(); + if (device!.generator != null) { + device.generator!.accept(); } - final List views = await device.vmService.getFlutterViews(); + final List views = await device.vmService!.getFlutterViews(); for (final FlutterView view in views) { globals.printTrace('Connected to $view.'); } @@ -351,10 +340,10 @@ class HotRunner extends ResidentRunner { @override Future run({ - Completer connectionInfoCompleter, - Completer appStartedCompleter, + Completer? connectionInfoCompleter, + Completer? appStartedCompleter, bool enableDevTools = false, - String route, + String? route, }) async { await _calculateTargetPlatform(); @@ -366,16 +355,16 @@ class HotRunner extends ResidentRunner { Duration totalLaunchAppTime = Duration.zero; final List> startupTasks = >[]; - for (final FlutterDevice device in flutterDevices) { + for (final FlutterDevice? device in flutterDevices) { // Here we initialize the frontend_server concurrently with the platform // build, reducing overall initialization time. This is safe because the first // invocation of the frontend server produces a full dill file that the // subsequent invocation in devfs will not overwrite. await runSourceGenerators(); - if (device.generator != null) { + if (device!.generator != null) { final Stopwatch compileTimer = Stopwatch()..start(); startupTasks.add( - device.generator.recompile( + device.generator!.recompile( mainFile.uri, [], // When running without a provided applicationBinary, the tool will @@ -384,14 +373,11 @@ class HotRunner extends ResidentRunner { // should only be displayed once. suppressErrors: applicationBinary == null, checkDartPluginRegistry: true, - outputPath: dillOutputPath ?? - getDefaultApplicationKernelPath( - trackWidgetCreation: debuggingOptions.buildInfo.trackWidgetCreation, - ), + outputPath: dillOutputPath, packageConfig: debuggingOptions.buildInfo.packageConfig, projectRootPath: FlutterProject.current().directory.absolute.path, fs: globals.fs, - ).then((CompilerOutput output) { + ).then((CompilerOutput? output) { compileTimer.stop(); totalCompileTime += compileTimer.elapsed; return output?.errorCount == 0; @@ -409,16 +395,16 @@ class HotRunner extends ResidentRunner { })); } - unawaited(appStartedCompleter?.future?.then((_) => HotEvent('reload-ready', - targetPlatform: _targetPlatform, - sdkName: _sdkName, - emulator: _emulator, + unawaited(appStartedCompleter?.future.then((_) => HotEvent('reload-ready', + targetPlatform: _targetPlatform!, + sdkName: _sdkName!, + emulator: _emulator!, fullRestart: false, fastReassemble: false, overallTimeInMs: appStartedTimer.elapsed.inMilliseconds, compileTimeInMs: totalCompileTime.inMilliseconds, transferTimeInMs: totalLaunchAppTime.inMilliseconds, - )?.send())); + ).send())); try { final List results = await Future.wait(startupTasks); @@ -441,11 +427,11 @@ class HotRunner extends ResidentRunner { ); } - Future> _initDevFS() async { + Future> _initDevFS() async { final String fsName = globals.fs.path.basename(projectRootPath); - return [ - for (final FlutterDevice device in flutterDevices) - await device.setupDevFS( + return [ + for (final FlutterDevice? device in flutterDevices) + await device!.setupDevFS( fsName, globals.fs.directory(projectRootPath), ), @@ -465,11 +451,11 @@ class HotRunner extends ResidentRunner { final Stopwatch findInvalidationTimer = _stopwatchFactory.createStopwatch('updateDevFS')..start(); final InvalidationResult invalidationResult = await projectFileInvalidator.findInvalidated( - lastCompiled: flutterDevices[0].devFS.lastCompiled, - urisToMonitor: flutterDevices[0].devFS.sources, + lastCompiled: flutterDevices[0]!.devFS!.lastCompiled, + urisToMonitor: flutterDevices[0]!.devFS!.sources, packagesPath: packagesFilePath, - asyncScanning: hotRunnerConfig.asyncScanning, - packageConfig: flutterDevices[0].devFS.lastPackageConfig + asyncScanning: hotRunnerConfig!.asyncScanning, + packageConfig: flutterDevices[0]!.devFS!.lastPackageConfig ?? debuggingOptions.buildInfo.packageConfig, ); findInvalidationTimer.stop(); @@ -484,11 +470,11 @@ class HotRunner extends ResidentRunner { } final UpdateFSReport results = UpdateFSReport( success: true, - scannedSourcesCount: flutterDevices[0].devFS.sources.length, + scannedSourcesCount: flutterDevices[0]!.devFS!.sources.length, findInvalidatedDuration: findInvalidationTimer.elapsed, ); - for (final FlutterDevice device in flutterDevices) { - results.incorporateResults(await device.updateDevFS( + for (final FlutterDevice? device in flutterDevices) { + results.incorporateResults(await device!.updateDevFS( mainUri: entrypointFile.absolute.uri, target: target, bundle: assetBundle, @@ -498,8 +484,8 @@ class HotRunner extends ResidentRunner { fullRestart: fullRestart, projectRootPath: projectRootPath, pathToReload: getReloadPath(fullRestart: fullRestart, swap: _swap), - invalidatedFiles: invalidationResult.uris, - packageConfig: invalidationResult.packageConfig, + invalidatedFiles: invalidationResult.uris!, + packageConfig: invalidationResult.packageConfig!, dillOutputPath: dillOutputPath, )); } @@ -507,18 +493,18 @@ class HotRunner extends ResidentRunner { } void _resetDirtyAssets() { - for (final FlutterDevice device in flutterDevices) { - device.devFS.assetPathsToEvict.clear(); + for (final FlutterDevice? device in flutterDevices) { + device!.devFS!.assetPathsToEvict.clear(); } } Future _cleanupDevFS() async { final List> futures = >[]; - for (final FlutterDevice device in flutterDevices) { - if (device.devFS != null) { + for (final FlutterDevice? device in flutterDevices) { + if (device!.devFS != null) { // Cleanup the devFS, but don't wait indefinitely. // We ignore any errors, because it's not clear what we would do anyway. - futures.add(device.devFS.destroy() + futures.add(device.devFS!.destroy() .timeout(const Duration(milliseconds: 250)) .catchError((dynamic error) { globals.printTrace('Ignored error while cleaning up DevFS: $error'); @@ -534,10 +520,10 @@ class HotRunner extends ResidentRunner { Uri main, Uri assetsDirectory, ) async { - final List views = await device.vmService.getFlutterViews(); + final List views = await device.vmService!.getFlutterViews(); await Future.wait(>[ for (final FlutterView view in views) - device.vmService.runInView( + device.vmService!.runInView( viewId: view.id, main: main, assetsDirectory: assetsDirectory, @@ -547,9 +533,9 @@ class HotRunner extends ResidentRunner { Future _launchFromDevFS() async { final List> futures = >[]; - for (final FlutterDevice device in flutterDevices) { - final Uri deviceEntryUri = device.devFS.baseUri.resolve(_swap ? 'main.dart.swap.dill' : 'main.dart.dill'); - final Uri deviceAssetsDirectoryUri = device.devFS.baseUri.resolveUri( + for (final FlutterDevice? device in flutterDevices) { + final Uri deviceEntryUri = device!.devFS!.baseUri!.resolve(_swap ? 'main.dart.swap.dill' : 'main.dart.dill'); + final Uri deviceAssetsDirectoryUri = device.devFS!.baseUri!.resolveUri( globals.fs.path.toUri(getAssetBuildDirectory())); futures.add(_launchInView(device, deviceEntryUri, @@ -559,46 +545,46 @@ class HotRunner extends ResidentRunner { } Future _restartFromSources({ - String reason, + String? reason, }) async { final Stopwatch restartTimer = Stopwatch()..start(); UpdateFSReport updatedDevFS; try { updatedDevFS = await _updateDevFS(fullRestart: true); } finally { - hotRunnerConfig.updateDevFSComplete(); + hotRunnerConfig!.updateDevFSComplete(); } if (!updatedDevFS.success) { - for (final FlutterDevice device in flutterDevices) { - if (device.generator != null) { - await device.generator.reject(); + for (final FlutterDevice? device in flutterDevices) { + if (device!.generator != null) { + await device.generator!.reject(); } } return OperationResult(1, 'DevFS synchronization failed'); } _resetDirtyAssets(); - for (final FlutterDevice device in flutterDevices) { + for (final FlutterDevice? device in flutterDevices) { // VM must have accepted the kernel binary, there will be no reload // report, so we let incremental compiler know that source code was accepted. - if (device.generator != null) { - device.generator.accept(); + if (device!.generator != null) { + device.generator!.accept(); } } // Check if the isolate is paused and resume it. final List> operations = >[]; - for (final FlutterDevice device in flutterDevices) { - final Set uiIsolatesIds = {}; - final List views = await device.vmService.getFlutterViews(); + for (final FlutterDevice? device in flutterDevices) { + final Set uiIsolatesIds = {}; + final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { if (view.uiIsolate == null) { continue; } - uiIsolatesIds.add(view.uiIsolate.id); + uiIsolatesIds.add(view.uiIsolate!.id); // Reload the isolate. - final Future reloadIsolate = device.vmService - .getIsolateOrNull(view.uiIsolate.id); - operations.add(reloadIsolate.then((vm_service.Isolate isolate) async { - if ((isolate != null) && isPauseEvent(isolate.pauseEvent.kind)) { + final Future reloadIsolate = device.vmService! + .getIsolateOrNull(view.uiIsolate!.id!); + operations.add(reloadIsolate.then((vm_service.Isolate? isolate) async { + if ((isolate != null) && isPauseEvent(isolate.pauseEvent!.kind!)) { // The embedder requires that the isolate is unpaused, because the // runInView method requires interaction with dart engine APIs that // are not thread-safe, and thus must be run on the same thread that @@ -612,13 +598,13 @@ class HotRunner extends ResidentRunner { // new isolates, which will be configured by the editor as they are // started. final List> breakpointAndExceptionRemoval = >[ - device.vmService.service.setIsolatePauseMode(isolate.id, + device.vmService!.service.setIsolatePauseMode(isolate.id!, exceptionPauseMode: vm_service.ExceptionPauseMode.kNone), - for (final vm_service.Breakpoint breakpoint in isolate.breakpoints) - device.vmService.service.removeBreakpoint(isolate.id, breakpoint.id), + for (final vm_service.Breakpoint breakpoint in isolate.breakpoints!) + device.vmService!.service.removeBreakpoint(isolate.id!, breakpoint.id!), ]; await Future.wait(breakpointAndExceptionRemoval); - await device.vmService.service.resume(view.uiIsolate.id); + await device.vmService!.service.resume(view.uiIsolate!.id!); } })); } @@ -626,12 +612,12 @@ class HotRunner extends ResidentRunner { // The engine handles killing and recreating isolates that it has spawned // ("uiIsolates"). The isolates that were spawned from these uiIsolates // will not be restarted, and so they must be manually killed. - final vm_service.VM vm = await device.vmService.service.getVM(); - for (final vm_service.IsolateRef isolateRef in vm.isolates) { + final vm_service.VM vm = await device.vmService!.service.getVM(); + for (final vm_service.IsolateRef isolateRef in vm.isolates!) { if (uiIsolatesIds.contains(isolateRef.id)) { continue; } - operations.add(device.vmService.service.kill(isolateRef.id) + operations.add(device.vmService!.service.kill(isolateRef.id!) .catchError((dynamic error, StackTrace stackTrace) { // Do nothing on a SentinelException since it means the isolate // has already been killed. @@ -666,7 +652,7 @@ class HotRunner extends ResidentRunner { /// Returns [true] if the reload was successful. /// Prints errors if [printErrors] is [true]. static bool validateReloadReport( - vm_service.ReloadReport reloadReport, { + vm_service.ReloadReport? reloadReport, { bool printErrors = true, }) { if (reloadReport == null) { @@ -676,7 +662,7 @@ class HotRunner extends ResidentRunner { return false; } final ReloadReportContents contents = ReloadReportContents.fromReloadReport(reloadReport); - if (!reloadReport.success) { + if (!reloadReport.success!) { if (printErrors) { globals.printError('Hot reload was rejected:'); for (final ReasonForCancelling reason in contents.notices) { @@ -691,11 +677,11 @@ class HotRunner extends ResidentRunner { @override Future restart({ bool fullRestart = false, - String reason, + String? reason, bool silent = false, bool pause = false, }) async { - if (flutterDevices.any((FlutterDevice device) => device.devFS == null)) { + if (flutterDevices.any((FlutterDevice? device) => device!.devFS == null)) { return OperationResult(1, 'Device initialization has not completed.'); } await _calculateTargetPlatform(); @@ -715,7 +701,7 @@ class HotRunner extends ResidentRunner { if (!silent) { globals.printStatus('Restarted application in ${getElapsedAsMilliseconds(timer.elapsed)}.'); } - unawaited(residentDevtoolsHandler.hotRestart(flutterDevices)); + unawaited(residentDevtoolsHandler!.hotRestart(flutterDevices)); return result; } final OperationResult result = await _hotReloadHelper( @@ -742,27 +728,27 @@ class HotRunner extends ResidentRunner { } Future _fullRestartHelper({ - String targetPlatform, - String sdkName, - bool emulator, - String reason, - bool silent, + String? targetPlatform, + String? sdkName, + bool? emulator, + String? reason, + bool? silent, }) async { if (!supportsRestart) { return OperationResult(1, 'hotRestart not supported'); } - Status status; - if (!silent) { + Status? status; + if (!silent!) { status = globals.logger.startProgress( 'Performing hot restart...', progressId: 'hot.restart', ); } OperationResult result; - String restartEvent; + String? restartEvent; try { final Stopwatch restartTimer = _stopwatchFactory.createStopwatch('fullRestartHelper')..start(); - if (!(await hotRunnerConfig.setupHotRestart())) { + if (!(await (hotRunnerConfig!.setupHotRestart() as FutureOr))) { return OperationResult(1, 'setupHotRestart failed'); } result = await _restartFromSources(reason: reason); @@ -771,18 +757,18 @@ class HotRunner extends ResidentRunner { restartEvent = 'restart-failed'; } else { HotEvent('restart', - targetPlatform: targetPlatform, - sdkName: sdkName, - emulator: emulator, + targetPlatform: targetPlatform!, + sdkName: sdkName!, + emulator: emulator!, fullRestart: true, reason: reason, fastReassemble: false, overallTimeInMs: restartTimer.elapsed.inMilliseconds, syncedBytes: result.updateFSReport?.syncedBytes, invalidatedSourcesCount: result.updateFSReport?.invalidatedSourcesCount, - transferTimeInMs: result.updateFSReport?.transferDuration?.inMilliseconds, - compileTimeInMs: result.updateFSReport?.compileDuration?.inMilliseconds, - findInvalidatedTimeInMs: result.updateFSReport?.findInvalidatedDuration?.inMilliseconds, + transferTimeInMs: result.updateFSReport?.transferDuration.inMilliseconds, + compileTimeInMs: result.updateFSReport?.compileDuration.inMilliseconds, + findInvalidatedTimeInMs: result.updateFSReport?.findInvalidatedDuration.inMilliseconds, scannedSourcesCount: result.updateFSReport?.scannedSourcesCount, ).send(); } @@ -797,9 +783,9 @@ class HotRunner extends ResidentRunner { // only handle the case when it failed here. if (restartEvent != null) { HotEvent(restartEvent, - targetPlatform: targetPlatform, - sdkName: sdkName, - emulator: emulator, + targetPlatform: targetPlatform!, + sdkName: sdkName!, + emulator: emulator!, fullRestart: true, reason: reason, fastReassemble: false, @@ -811,11 +797,11 @@ class HotRunner extends ResidentRunner { } Future _hotReloadHelper({ - String targetPlatform, - String sdkName, - bool emulator, - String reason, - bool pause, + String? targetPlatform, + String? sdkName, + bool? emulator, + String? reason, + bool? pause, }) async { Status status = globals.logger.startProgress( 'Performing hot reload...', @@ -830,7 +816,7 @@ class HotRunner extends ResidentRunner { reason: reason, pause: pause, onSlow: (String message) { - status?.cancel(); + status.cancel(); status = globals.logger.startProgress( message, progressId: 'hot.reload', @@ -847,18 +833,18 @@ class HotRunner extends ResidentRunner { 'restart the app.\n' '${error.message} (error code: ${error.code})'; HotEvent('reload-barred', - targetPlatform: targetPlatform, - sdkName: sdkName, - emulator: emulator, + targetPlatform: targetPlatform!, + sdkName: sdkName!, + emulator: emulator!, fullRestart: false, reason: reason, fastReassemble: false, ).send(); } else { HotEvent('exception', - targetPlatform: targetPlatform, - sdkName: sdkName, - emulator: emulator, + targetPlatform: targetPlatform!, + sdkName: sdkName!, + emulator: emulator!, fullRestart: false, reason: reason, fastReassemble: false, @@ -872,16 +858,16 @@ class HotRunner extends ResidentRunner { } Future _reloadSources({ - String targetPlatform, - String sdkName, - bool emulator, - bool pause = false, - String reason, - void Function(String message) onSlow, + String? targetPlatform, + String? sdkName, + bool? emulator, + bool? pause = false, + String? reason, + void Function(String message)? onSlow, }) async { - final Map> viewCache = >{}; - for (final FlutterDevice device in flutterDevices) { - final List views = await device.vmService.getFlutterViews(); + final Map> viewCache = >{}; + for (final FlutterDevice? device in flutterDevices) { + final List views = await device!.vmService!.getFlutterViews(); viewCache[device] = views; for (final FlutterView view in views) { if (view.uiIsolate == null) { @@ -891,7 +877,7 @@ class HotRunner extends ResidentRunner { } final Stopwatch reloadTimer = _stopwatchFactory.createStopwatch('reloadSources:reload')..start(); - if (!(await hotRunnerConfig.setupHotReload())) { + if (!(await (hotRunnerConfig!.setupHotReload() as FutureOr))) { return OperationResult(1, 'setupHotReload failed'); } final Stopwatch devFSTimer = Stopwatch()..start(); @@ -899,7 +885,7 @@ class HotRunner extends ResidentRunner { try { updatedDevFS= await _updateDevFS(); } finally { - hotRunnerConfig.updateDevFSComplete(); + hotRunnerConfig!.updateDevFSComplete(); } // Record time it took to synchronize to DevFS. bool shouldReportReloadTime = true; @@ -913,7 +899,7 @@ class HotRunner extends ResidentRunner { String reloadMessage = 'Reloaded 0 libraries'; final Stopwatch reloadVMTimer = _stopwatchFactory.createStopwatch('reloadSources:vm')..start(); - final Map firstReloadDetails = {}; + final Map firstReloadDetails = {}; if (updatedDevFS.invalidatedSourcesCount > 0) { final OperationResult result = await _reloadSourcesHelper( this, @@ -965,22 +951,20 @@ class HotRunner extends ResidentRunner { // Relation of [invalidatedSourcesCount] to [syncedLibraryCount] should help // understand sync/transfer "overhead" of updating this number of source files. HotEvent('reload', - targetPlatform: targetPlatform, - sdkName: sdkName, - emulator: emulator, + targetPlatform: targetPlatform!, + sdkName: sdkName!, + emulator: emulator!, fullRestart: false, reason: reason, overallTimeInMs: reloadInMs, - finalLibraryCount: firstReloadDetails['finalLibraryCount'] as int ?? 0, - syncedLibraryCount: firstReloadDetails['receivedLibraryCount'] as int ?? 0, - syncedClassesCount: firstReloadDetails['receivedClassesCount'] as int ?? 0, - syncedProceduresCount: firstReloadDetails['receivedProceduresCount'] as int ?? 0, + finalLibraryCount: firstReloadDetails['finalLibraryCount'] as int? ?? 0, + syncedLibraryCount: firstReloadDetails['receivedLibraryCount'] as int? ?? 0, + syncedClassesCount: firstReloadDetails['receivedClassesCount'] as int? ?? 0, + syncedProceduresCount: firstReloadDetails['receivedProceduresCount'] as int? ?? 0, syncedBytes: updatedDevFS.syncedBytes, invalidatedSourcesCount: updatedDevFS.invalidatedSourcesCount, transferTimeInMs: updatedDevFS.transferDuration.inMilliseconds, - fastReassemble: featureFlags.isSingleWidgetReloadEnabled - ? updatedDevFS.fastReassembleClassName != null - : null, + fastReassemble: featureFlags.isSingleWidgetReloadEnabled && updatedDevFS.fastReassembleClassName != null, compileTimeInMs: updatedDevFS.compileDuration.inMilliseconds, findInvalidatedTimeInMs: updatedDevFS.findInvalidatedDuration.inMilliseconds, scannedSourcesCount: updatedDevFS.scannedSourcesCount, @@ -1005,7 +989,7 @@ class HotRunner extends ResidentRunner { } @override - void printHelp({ @required bool details }) { + void printHelp({ required bool details }) { globals.printStatus('Flutter run key commands.'); commandHelp.r.print(); if (supportsRestart) { @@ -1040,51 +1024,51 @@ class HotRunner extends ResidentRunner { @visibleForTesting Future evictDirtyAssets() async { - final List>> futures = >>[]; - for (final FlutterDevice device in flutterDevices) { - if (device.devFS.assetPathsToEvict.isEmpty) { + final List?>> futures = >>[]; + for (final FlutterDevice? device in flutterDevices) { + if (device!.devFS!.assetPathsToEvict.isEmpty) { continue; } - final List views = await device.vmService.getFlutterViews(); + final List views = await device.vmService!.getFlutterViews(); // If this is the first time we update the assets, make sure to call the setAssetDirectory - if (!device.devFS.hasSetAssetDirectory) { - final Uri deviceAssetsDirectoryUri = device.devFS.baseUri.resolveUri(globals.fs.path.toUri(getAssetBuildDirectory())); + if (!device.devFS!.hasSetAssetDirectory) { + final Uri deviceAssetsDirectoryUri = device.devFS!.baseUri!.resolveUri(globals.fs.path.toUri(getAssetBuildDirectory())); await Future.wait(views.map>( - (FlutterView view) => device.vmService.setAssetDirectory( + (FlutterView view) => device.vmService!.setAssetDirectory( assetsDirectory: deviceAssetsDirectoryUri, - uiIsolateId: view.uiIsolate.id, + uiIsolateId: view.uiIsolate!.id, viewId: view.id, ) )); for (final FlutterView view in views) { globals.printTrace('Set asset directory in $view.'); } - device.devFS.hasSetAssetDirectory = true; + device.devFS!.hasSetAssetDirectory = true; } if (views.first.uiIsolate == null) { globals.printError('Application isolate not found for $device'); continue; } - for (final String assetPath in device.devFS.assetPathsToEvict) { + for (final String assetPath in device.devFS!.assetPathsToEvict) { futures.add( - device.vmService + device.vmService! .flutterEvictAsset( assetPath, - isolateId: views.first.uiIsolate.id, + isolateId: views.first.uiIsolate!.id!, ) ); } - device.devFS.assetPathsToEvict.clear(); + device.devFS!.assetPathsToEvict.clear(); } - return Future.wait>(futures); + await Future.wait?>(futures); } @override Future cleanupAfterSignal() async { await stopEchoingDeviceLog(); - await hotRunnerConfig.runPreShutdownOperations(); + await hotRunnerConfig!.runPreShutdownOperations(); if (_didAttach) { appFinished(); } else { @@ -1095,49 +1079,49 @@ class HotRunner extends ResidentRunner { @override Future preExit() async { await _cleanupDevFS(); - await hotRunnerConfig.runPreShutdownOperations(); + await hotRunnerConfig!.runPreShutdownOperations(); await super.preExit(); } @override Future cleanupAtFinish() async { - for (final FlutterDevice flutterDevice in flutterDevices) { - await flutterDevice.device.dispose(); + for (final FlutterDevice? flutterDevice in flutterDevices) { + await flutterDevice!.device!.dispose(); } await _cleanupDevFS(); - await residentDevtoolsHandler.shutdown(); + await residentDevtoolsHandler!.shutdown(); await stopEchoingDeviceLog(); } } typedef ReloadSourcesHelper = Future Function( HotRunner hotRunner, - List flutterDevices, - bool pause, + List flutterDevices, + bool? pause, Map firstReloadDetails, - String targetPlatform, - String sdkName, - bool emulator, - String reason, + String? targetPlatform, + String? sdkName, + bool? emulator, + String? reason, ); Future _defaultReloadSourcesHelper( HotRunner hotRunner, - List flutterDevices, - bool pause, + List flutterDevices, + bool? pause, Map firstReloadDetails, - String targetPlatform, - String sdkName, - bool emulator, - String reason, + String? targetPlatform, + String? sdkName, + bool? emulator, + String? reason, ) async { final Stopwatch vmReloadTimer = Stopwatch()..start(); const String entryPath = 'main.dart.incremental.dill'; final List> allReportsFutures = >[]; - for (final FlutterDevice device in flutterDevices) { + for (final FlutterDevice? device in flutterDevices) { final List> reportFutures = await _reloadDeviceSources( - device, + device!, entryPath, pause: pause, ); @@ -1160,9 +1144,9 @@ Future _defaultReloadSourcesHelper( if (!HotRunner.validateReloadReport(reloadReport)) { // Reload failed. HotEvent('reload-reject', - targetPlatform: targetPlatform, - sdkName: sdkName, - emulator: emulator, + targetPlatform: targetPlatform!, + sdkName: sdkName!, + emulator: emulator!, fullRestart: false, reason: reason, fastReassemble: false, @@ -1176,10 +1160,10 @@ Future _defaultReloadSourcesHelper( // Collect stats only from the first device. If/when run -d all is // refactored, we'll probably need to send one hot reload/restart event // per device to analytics. - firstReloadDetails.addAll(castStringKeyedMap(reloadReport.json['details'])); - final Map details = reloadReport.json['details'] as Map; - final int loadedLibraryCount = details['loadedLibraryCount'] as int; - final int finalLibraryCount = details['finalLibraryCount'] as int; + firstReloadDetails.addAll(castStringKeyedMap(reloadReport.json!['details'])!); + final Map details = reloadReport.json!['details'] as Map; + final int? loadedLibraryCount = details['loadedLibraryCount'] as int?; + final int? finalLibraryCount = details['finalLibraryCount'] as int?; globals.printTrace('reloaded $loadedLibraryCount of $finalLibraryCount libraries'); // reloadMessage = 'Reloaded $loadedLibraryCount of $finalLibraryCount libraries'; // Record time it took for the VM to reload the sources. @@ -1190,67 +1174,67 @@ Future _defaultReloadSourcesHelper( Future>> _reloadDeviceSources( FlutterDevice device, String entryPath, { - bool pause = false, + bool? pause = false, }) async { - final String deviceEntryUri = device.devFS.baseUri + final String deviceEntryUri = device.devFS!.baseUri! .resolve(entryPath).toString(); - final vm_service.VM vm = await device.vmService.service.getVM(); + final vm_service.VM vm = await device.vmService!.service.getVM(); return >[ - for (final vm_service.IsolateRef isolateRef in vm.isolates) - device.vmService.service.reloadSources( - isolateRef.id, + for (final vm_service.IsolateRef isolateRef in vm.isolates!) + device.vmService!.service.reloadSources( + isolateRef.id!, pause: pause, rootLibUri: deviceEntryUri, ), ]; } -void _resetDevFSCompileTime(List flutterDevices) { - for (final FlutterDevice device in flutterDevices) { - device.devFS.resetLastCompiled(); +void _resetDevFSCompileTime(List flutterDevices) { + for (final FlutterDevice? device in flutterDevices) { + device!.devFS!.resetLastCompiled(); } } @visibleForTesting class ReassembleResult { ReassembleResult(this.reassembleViews, this.failedReassemble, this.shouldReportReloadTime); - final Map reassembleViews; + final Map reassembleViews; final bool failedReassemble; final bool shouldReportReloadTime; } typedef ReassembleHelper = Future Function( - List flutterDevices, - Map> viewCache, - void Function(String message) onSlow, + List flutterDevices, + Map> viewCache, + void Function(String message)? onSlow, String reloadMessage, - String fastReassembleClassName, + String? fastReassembleClassName, ); Future _defaultReassembleHelper( - List flutterDevices, - Map> viewCache, - void Function(String message) onSlow, + List flutterDevices, + Map> viewCache, + void Function(String message)? onSlow, String reloadMessage, - String fastReassembleClassName, + String? fastReassembleClassName, ) async { // Check if any isolates are paused and reassemble those that aren't. - final Map reassembleViews = {}; + final Map reassembleViews = {}; final List> reassembleFutures = >[]; - String serviceEventKind; + String? serviceEventKind; int pausedIsolatesFound = 0; bool failedReassemble = false; bool shouldReportReloadTime = true; - for (final FlutterDevice device in flutterDevices) { - final List views = viewCache[device]; + for (final FlutterDevice? device in flutterDevices) { + final List views = viewCache[device]!; for (final FlutterView view in views) { // Check if the isolate is paused, and if so, don't reassemble. Ignore the // PostPauseEvent event - the client requesting the pause will resume the app. - final vm_service.Isolate isolate = await device.vmService - .getIsolateOrNull(view.uiIsolate.id); - final vm_service.Event pauseEvent = isolate?.pauseEvent; + final vm_service.Isolate? isolate = await device!.vmService! + .getIsolateOrNull(view.uiIsolate!.id!); + final vm_service.Event? pauseEvent = isolate?.pauseEvent; if (pauseEvent != null - && isPauseEvent(pauseEvent.kind) + && isPauseEvent(pauseEvent.kind!) && pauseEvent.kind != vm_service.EventKind.kPausePostRequest) { pausedIsolatesFound += 1; if (serviceEventKind == null) { @@ -1264,25 +1248,25 @@ Future _defaultReassembleHelper( // of a full reassemble. Future reassembleWork; if (fastReassembleClassName != null) { - reassembleWork = device.vmService.flutterFastReassemble( - isolateId: view.uiIsolate.id, + reassembleWork = device.vmService!.flutterFastReassemble( + isolateId: view.uiIsolate!.id!, className: fastReassembleClassName, ); } else { - reassembleWork = device.vmService.flutterReassemble( - isolateId: view.uiIsolate.id, + reassembleWork = device.vmService!.flutterReassemble( + isolateId: view.uiIsolate!.id!, ); } reassembleFutures.add(reassembleWork.catchError((dynamic error) { failedReassemble = true; - globals.printError('Reassembling ${view.uiIsolate.name} failed: $error'); + globals.printError('Reassembling ${view.uiIsolate!.name} failed: $error'); }, test: (dynamic error) => error is Exception)); } } } if (pausedIsolatesFound > 0) { if (onSlow != null) { - onSlow('${_describePausedIsolates(pausedIsolatesFound, serviceEventKind)}; interface might not update.'); + onSlow('${_describePausedIsolates(pausedIsolatesFound, serviceEventKind!)}; interface might not update.'); } if (reassembleViews.isEmpty) { globals.printTrace('Skipping reassemble because all isolates are paused.'); @@ -1293,29 +1277,29 @@ Future _defaultReassembleHelper( globals.printTrace('Reassembling application'); - final Future reassembleFuture = Future.wait(reassembleFutures); + final Future reassembleFuture = Future.wait(reassembleFutures).then((void _) => null); await reassembleFuture.timeout( const Duration(seconds: 2), onTimeout: () async { if (pausedIsolatesFound > 0) { shouldReportReloadTime = false; - return; // probably no point waiting, they're probably deadlocked and we've already warned. + return ; // probably no point waiting, they're probably deadlocked and we've already warned. } // Check if any isolate is newly paused. globals.printTrace('This is taking a long time; will now check for paused isolates.'); int postReloadPausedIsolatesFound = 0; - String serviceEventKind; + String? serviceEventKind; for (final FlutterView view in reassembleViews.keys) { - final vm_service.Isolate isolate = await reassembleViews[view] - .getIsolateOrNull(view.uiIsolate.id); + final vm_service.Isolate? isolate = await reassembleViews[view]! + .getIsolateOrNull(view.uiIsolate!.id!); if (isolate == null) { continue; } - if (isolate.pauseEvent != null && isPauseEvent(isolate.pauseEvent.kind)) { + if (isolate.pauseEvent != null && isPauseEvent(isolate.pauseEvent!.kind!)) { postReloadPausedIsolatesFound += 1; if (serviceEventKind == null) { - serviceEventKind = isolate.pauseEvent.kind; - } else if (serviceEventKind != isolate.pauseEvent.kind) { + serviceEventKind = isolate.pauseEvent!.kind; + } else if (serviceEventKind != isolate.pauseEvent!.kind) { serviceEventKind = ''; // many kinds } } @@ -1327,8 +1311,9 @@ Future _defaultReassembleHelper( } shouldReportReloadTime = false; if (onSlow != null) { - onSlow('${_describePausedIsolates(postReloadPausedIsolatesFound, serviceEventKind)}.'); + onSlow('${_describePausedIsolates(postReloadPausedIsolatesFound, serviceEventKind!)}.'); } + return; }, ); return ReassembleResult(reassembleViews, failedReassemble, shouldReportReloadTime); @@ -1381,17 +1366,17 @@ class InvalidationResult { this.packageConfig, }); - final List uris; - final PackageConfig packageConfig; + final List? uris; + final PackageConfig? packageConfig; } /// The [ProjectFileInvalidator] track the dependencies for a running /// application to determine when they are dirty. class ProjectFileInvalidator { ProjectFileInvalidator({ - @required FileSystem fileSystem, - @required Platform platform, - @required Logger logger, + required FileSystem fileSystem, + required Platform platform, + required Logger logger, }): _fileSystem = fileSystem, _platform = platform, _logger = logger; @@ -1412,10 +1397,10 @@ class ProjectFileInvalidator { static const int _kMaxPendingStats = 8; Future findInvalidated({ - @required DateTime lastCompiled, - @required List urisToMonitor, - @required String packagesPath, - @required PackageConfig packageConfig, + required DateTime? lastCompiled, + required List urisToMonitor, + required String packagesPath, + required PackageConfig packageConfig, bool asyncScanning = false, }) async { assert(urisToMonitor != null); @@ -1516,18 +1501,18 @@ class ProjectFileInvalidator { class ReloadReportContents { factory ReloadReportContents.fromReloadReport(vm_service.ReloadReport report) { final List reasons = []; - final Object notices = report.json['notices']; + final Object? notices = report.json!['notices']; if (notices is! List) { return ReloadReportContents._(report.success, reasons, report); } - for (final Object obj in notices as List) { + for (final Object? obj in notices) { if (obj is! Map) { continue; } - final Map notice = obj as Map; + final Map notice = obj; reasons.add(ReasonForCancelling( message: notice['message'] is String - ? notice['message'] as String + ? notice['message'] as String? : 'Unknown Error', )); } @@ -1541,7 +1526,7 @@ class ReloadReportContents { this.report, ); - final bool success; + final bool? success; final List notices; final vm_service.ReloadReport report; } @@ -1555,7 +1540,7 @@ class ReasonForCancelling { this.message, }); - final String message; + final String? message; @override String toString() { diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index d3716fc01174..e53335fd1665 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -69,7 +69,7 @@ class FlutterCommandResult { /// Optional data that can be appended to the timing event. /// https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#timingLabel /// Do not add PII. - final List? timingLabelParts; + final List? timingLabelParts; /// Optional epoch time when the command's non-interactive wait time is /// complete during the command's execution. Use to measure user perceivable @@ -1265,7 +1265,7 @@ abstract class FlutterCommand extends Command { CommandResultEvent(commandPath, commandResult.toString()).send(); // Send timing. - final List labels = [ + final List labels = [ if (commandResult.exitStatus != null) getEnumName(commandResult.exitStatus), if (commandResult.timingLabelParts?.isNotEmpty ?? false) @@ -1273,7 +1273,7 @@ abstract class FlutterCommand extends Command { ]; final String label = labels - .where((String label) => !_isBlank(label)) + .where((String? label) => label != null && !_isBlank(label)) .join('-'); globals.flutterUsage.sendTiming( 'flutter', diff --git a/packages/flutter_tools/lib/src/test/coverage_collector.dart b/packages/flutter_tools/lib/src/test/coverage_collector.dart index 52f27b328af9..2402cb59fa82 100644 --- a/packages/flutter_tools/lib/src/test/coverage_collector.dart +++ b/packages/flutter_tools/lib/src/test/coverage_collector.dart @@ -2,7 +2,7 @@ // 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:coverage/coverage.dart' as coverage; import 'package:meta/meta.dart'; @@ -19,7 +19,7 @@ import 'watcher.dart'; /// A class that collects code coverage data during test runs. class CoverageCollector extends TestWatcher { - CoverageCollector({this.libraryNames, this.verbose = true, @required this.packagesPath}); + CoverageCollector({this.libraryNames, this.verbose = true, required this.packagesPath}); /// True when log messages should be emitted. final bool verbose; @@ -29,11 +29,11 @@ class CoverageCollector extends TestWatcher { final String packagesPath; /// Map of file path to coverage hit map for that file. - Map _globalHitmap; + Map? _globalHitmap; /// The names of the libraries to gather coverage for. If null, all libraries /// will be accepted. - Set libraryNames; + Set? libraryNames; @override Future handleFinishedTest(TestDevice testDevice) async { @@ -56,7 +56,7 @@ class CoverageCollector extends TestWatcher { if (_globalHitmap == null) { _globalHitmap = hitmap; } else { - _globalHitmap.merge(hitmap); + _globalHitmap!.merge(hitmap); } } @@ -107,7 +107,7 @@ class CoverageCollector extends TestWatcher { Future collectCoverage(TestDevice testDevice) async { assert(testDevice != null); - Map data; + Map? data; final Future processComplete = testDevice.finished.catchError( (Object error) => throw Exception( @@ -134,7 +134,7 @@ class CoverageCollector extends TestWatcher { _logMessage('Merging coverage data...'); _addHitmap(await coverage.HitMap.parseJson( - data['coverage'] as List>, + data!['coverage'] as List>, packagePath: packageDirectory, checkIgnoredLines: true, )); @@ -145,10 +145,10 @@ class CoverageCollector extends TestWatcher { /// /// This will not start any collection tasks. It us up to the caller of to /// call [collectCoverage] for each process first. - Future finalizeCoverage({ - String Function(Map hitmap) formatter, - coverage.Resolver resolver, - Directory coverageDirectory, + Future finalizeCoverage({ + String Function(Map hitmap)? formatter, + coverage.Resolver? resolver, + Directory? coverageDirectory, }) async { if (_globalHitmap == null) { return null; @@ -160,15 +160,15 @@ class CoverageCollector extends TestWatcher { ? [globals.fs.path.join(packagePath, 'lib')] : [coverageDirectory.path]; formatter = (Map hitmap) => hitmap - .formatLcov(resolver, reportOn: reportOn, basePath: packagePath); + .formatLcov(resolver!, reportOn: reportOn, basePath: packagePath); } - final String result = formatter(_globalHitmap); + final String result = formatter(_globalHitmap!); _globalHitmap = null; return result; } - Future collectCoverageData(String coveragePath, { bool mergeCoverageData = false, Directory coverageDirectory }) async { - final String coverageData = await finalizeCoverage( + Future collectCoverageData(String? coveragePath, { bool mergeCoverageData = false, Directory? coverageDirectory }) async { + final String? coverageData = await finalizeCoverage( coverageDirectory: coverageDirectory, ); _logMessage('coverage information collection complete'); @@ -225,15 +225,15 @@ class CoverageCollector extends TestWatcher { Future handleTestTimedOut(TestDevice testDevice) async { } } -Future _defaultConnect(Uri serviceUri) { +Future _defaultConnect(Uri? serviceUri) { return connectToVmService( - serviceUri, compression: CompressionOptions.compressionOff, logger: globals.logger,); + serviceUri!, compression: CompressionOptions.compressionOff, logger: globals.logger,); } -Future> collect(Uri serviceUri, Set libraryNames, { +Future> collect(Uri? serviceUri, Set? libraryNames, { bool waitPaused = false, - String debugName, - Future Function(Uri) connector = _defaultConnect, + String? debugName, + Future Function(Uri?) connector = _defaultConnect, @visibleForTesting bool forceSequential = false, }) async { final FlutterVmService vmService = await connector(serviceUri); @@ -244,31 +244,31 @@ Future> collect(Uri serviceUri, Set libraryNames, { Future> _getAllCoverage( vm_service.VmService service, - Set libraryNames, + Set? libraryNames, bool forceSequential, ) async { final vm_service.Version version = await service.getVersion(); - final bool libraryFilters = (version.major == 3 && version.minor >= 57) || version.major > 3; + final bool libraryFilters = (version.major == 3 && version.minor! >= 57) || version.major! > 3; final vm_service.VM vm = await service.getVM(); final List> coverage = >[]; - bool libraryPredicate(String libraryName) { + bool libraryPredicate(String? libraryName) { if (libraryNames == null) { return true; } - final Uri uri = Uri.parse(libraryName); + final Uri uri = Uri.parse(libraryName!); if (uri.scheme != 'package') { return false; } final String scope = uri.path.split('/').first; return libraryNames.contains(scope); } - for (final vm_service.IsolateRef isolateRef in vm.isolates) { - if (isolateRef.isSystemIsolate) { + for (final vm_service.IsolateRef isolateRef in vm.isolates!) { + if (isolateRef.isSystemIsolate!) { continue; } if (libraryFilters) { final vm_service.SourceReport sourceReport = await service.getSourceReport( - isolateRef.id, + isolateRef.id!, ['Coverage'], forceCompile: true, reportLines: true, @@ -283,7 +283,7 @@ Future> _getAllCoverage( } else { vm_service.ScriptList scriptList; try { - scriptList = await service.getScripts(isolateRef.id); + scriptList = await service.getScripts(isolateRef.id!); } on vm_service.SentinelException { continue; } @@ -294,14 +294,14 @@ Future> _getAllCoverage( // For each ScriptRef loaded into the VM, load the corresponding Script // and SourceReport object. - for (final vm_service.ScriptRef script in scriptList.scripts) { - final String libraryUri = script.uri; + for (final vm_service.ScriptRef script in scriptList.scripts!) { + final String? libraryUri = script.uri; if (!libraryPredicate(libraryUri)) { continue; } - final String scriptId = script.id; + final String? scriptId = script.id; final Future getSourceReport = service.getSourceReport( - isolateRef.id, + isolateRef.id!, ['Coverage'], scriptId: scriptId, forceCompile: true, @@ -328,36 +328,36 @@ void _buildCoverageMap( List sourceReports, List> coverage, ) { - final Map> hitMaps = >{}; + final Map> hitMaps = >{}; for (final vm_service.SourceReport sourceReport in sourceReports) { - for (final vm_service.SourceReportRange range in sourceReport.ranges) { - final vm_service.SourceReportCoverage coverage = range.coverage; + for (final vm_service.SourceReportRange range in sourceReport.ranges!) { + final vm_service.SourceReportCoverage? coverage = range.coverage; // Coverage reports may sometimes be null for a Script. if (coverage == null) { continue; } - final vm_service.ScriptRef scriptRef = sourceReport.scripts[range.scriptIndex]; - final String uri = scriptRef.uri; + final vm_service.ScriptRef scriptRef = sourceReport.scripts![range.scriptIndex!]; + final String? uri = scriptRef.uri; hitMaps[uri] ??= {}; - final Map hitMap = hitMaps[uri]; - final List hits = coverage.hits; - final List misses = coverage.misses; + final Map? hitMap = hitMaps[uri]; + final List? hits = coverage.hits; + final List? misses = coverage.misses; if (hits != null) { for (final int line in hits) { - final int current = hitMap[line] ?? 0; + final int current = hitMap![line] ?? 0; hitMap[line] = current + 1; } } if (misses != null) { for (final int line in misses) { - hitMap[line] ??= 0; + hitMap![line] ??= 0; } } } } - hitMaps.forEach((String uri, Map hitMap) { - coverage.add(_toScriptCoverageJson(uri, hitMap)); + hitMaps.forEach((String? uri, Map hitMap) { + coverage.add(_toScriptCoverageJson(uri!, hitMap)); }); } diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index d16113813ff3..60d0cc0584b7 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -2,7 +2,7 @@ // 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'; @@ -47,22 +47,22 @@ typedef PlatformPluginRegistration = void Function(FlutterPlatform platform); /// main()`), you can set an observatory port explicitly. FlutterPlatform installHook({ TestWrapper testWrapper = const TestWrapper(), - @required String shellPath, - @required DebuggingOptions debuggingOptions, - TestWatcher watcher, + required String shellPath, + required DebuggingOptions debuggingOptions, + TestWatcher? watcher, bool enableObservatory = false, bool machine = false, - String precompiledDillPath, - Map precompiledDillFiles, + String? precompiledDillPath, + Map? precompiledDillFiles, bool updateGoldens = false, - String testAssetDirectory, + String? testAssetDirectory, InternetAddressType serverType = InternetAddressType.IPv4, - Uri projectRootDirectory, - FlutterProject flutterProject, - String icudtlPath, - PlatformPluginRegistration platformPluginRegistration, - Device integrationTestDevice, - String integrationTestUserIdentifier, + Uri? projectRootDirectory, + FlutterProject? flutterProject, + String? icudtlPath, + PlatformPluginRegistration? platformPluginRegistration, + Device? integrationTestDevice, + String? integrationTestUserIdentifier, }) { assert(testWrapper != null); assert(enableObservatory || (!debuggingOptions.startPaused && debuggingOptions.hostVmServicePort == null)); @@ -119,9 +119,9 @@ FlutterPlatform installHook({ // NOTE: this API is used by the fuchsia source tree, do not add new // required or position parameters. String generateTestBootstrap({ - @required Uri testUrl, - @required InternetAddress host, - File testConfigFile, + required Uri testUrl, + required InternetAddress host, + File? testConfigFile, bool updateGoldens = false, String languageVersionHeader = '', bool nullSafety = false, @@ -271,8 +271,8 @@ typedef Finalizer = Future Function(); /// The flutter test platform used to integrate with package:test. class FlutterPlatform extends PlatformPlugin { FlutterPlatform({ - @required this.shellPath, - @required this.debuggingOptions, + required this.shellPath, + required this.debuggingOptions, this.watcher, this.enableObservatory, this.machine, @@ -290,26 +290,26 @@ class FlutterPlatform extends PlatformPlugin { final String shellPath; final DebuggingOptions debuggingOptions; - final TestWatcher watcher; - final bool enableObservatory; - final bool machine; - final InternetAddress host; - final String precompiledDillPath; - final Map precompiledDillFiles; - final bool updateGoldens; - final String testAssetDirectory; - final Uri projectRootDirectory; - final FlutterProject flutterProject; - final String icudtlPath; + final TestWatcher? watcher; + final bool? enableObservatory; + final bool? machine; + final InternetAddress? host; + final String? precompiledDillPath; + final Map? precompiledDillFiles; + final bool? updateGoldens; + final String? testAssetDirectory; + final Uri? projectRootDirectory; + final FlutterProject? flutterProject; + final String? icudtlPath; /// The device to run the test on for Integration Tests. /// /// If this is null, the test will run as a regular test with the Flutter /// Tester; otherwise it will run as a Integration Test on this device. - final Device integrationTestDevice; + final Device? integrationTestDevice; bool get _isIntegrationTest => integrationTestDevice != null; - final String integrationTestUserIdentifier; + final String? integrationTestUserIdentifier; final FontConfigManager _fontConfigManager = FontConfigManager(); @@ -317,7 +317,7 @@ class FlutterPlatform extends PlatformPlugin { /// /// To speed up compilation, each compile is initialized from an existing /// dill file from previous runs, if possible. - TestCompiler compiler; + TestCompiler? compiler; // Each time loadChannel() is called, we spin up a local WebSocket server, // then spin up the engine in a subprocess. We pass the engine a Dart file @@ -361,7 +361,7 @@ class FlutterPlatform extends PlatformPlugin { _testCount += 1; final StreamController localController = StreamController(); final StreamController remoteController = StreamController(); - final Completer<_AsyncError> testCompleteCompleter = Completer<_AsyncError>(); + final Completer<_AsyncError?> testCompleteCompleter = Completer<_AsyncError?>(); final _FlutterPlatformStreamSinkWrapper remoteSink = _FlutterPlatformStreamSinkWrapper( remoteController.sink, testCompleteCompleter.future, @@ -384,17 +384,17 @@ class FlutterPlatform extends PlatformPlugin { List definitions, List typeDefinitions, String libraryUri, - String klass, + String? klass, bool isStatic, ) async { - if (compiler == null || compiler.compiler == null) { + if (compiler == null || compiler!.compiler == null) { throw Exception('Compiler is not set up properly to compile $expression'); } - final CompilerOutput compilerOutput = - await compiler.compiler.compileExpression(expression, definitions, + final CompilerOutput? compilerOutput = + await compiler!.compiler!.compileExpression(expression, definitions, typeDefinitions, libraryUri, klass, isStatic); if (compilerOutput != null && compilerOutput.expressionData != null) { - return base64.encode(compilerOutput.expressionData); + return base64.encode(compilerOutput.expressionData!); } throw Exception('Failed to compile $expression'); } @@ -404,7 +404,7 @@ class FlutterPlatform extends PlatformPlugin { return IntegrationTestTestDevice( id: ourTestCount, debuggingOptions: debuggingOptions, - device: integrationTestDevice, + device: integrationTestDevice!, userIdentifier: integrationTestUserIdentifier, ); } @@ -415,7 +415,7 @@ class FlutterPlatform extends PlatformPlugin { processManager: globals.processManager, logger: globals.logger, shellPath: shellPath, - enableObservatory: enableObservatory, + enableObservatory: enableObservatory!, machine: machine, debuggingOptions: debuggingOptions, host: host, @@ -427,14 +427,14 @@ class FlutterPlatform extends PlatformPlugin { ); } - Future<_AsyncError> _startTest( + Future<_AsyncError?> _startTest( String testPath, StreamChannel testHarnessChannel, int ourTestCount, ) async { globals.printTrace('test $ourTestCount: starting test $testPath'); - _AsyncError outOfBandError; // error that we couldn't send to the harness that we need to send via our future + _AsyncError? outOfBandError; // error that we couldn't send to the harness that we need to send via our future final List finalizers = []; // Will be run in reverse order. bool controllerSinkClosed = false; @@ -447,7 +447,7 @@ class FlutterPlatform extends PlatformPlugin { // If a kernel file is given, then use that to launch the test. // If mapping is provided, look kernel file from mapping. // If all fails, create a "listener" dart that invokes actual test. - String mainDart; + String? mainDart; if (precompiledDillPath != null) { mainDart = precompiledDillPath; // When start paused is specified, it means that the user is likely @@ -457,10 +457,10 @@ class FlutterPlatform extends PlatformPlugin { compiler ??= TestCompiler(debuggingOptions.buildInfo, flutterProject, precompiledDillPath: precompiledDillPath); final Uri testUri = globals.fs.file(testPath).uri; // Trigger a compilation to initialize the resident compiler. - unawaited(compiler.compile(testUri)); + unawaited(compiler!.compile(testUri)); } } else if (precompiledDillFiles != null) { - mainDart = precompiledDillFiles[testPath]; + mainDart = precompiledDillFiles![testPath]; } else { mainDart = _createListenerDart(finalizers, ourTestCount, testPath); @@ -468,7 +468,7 @@ class FlutterPlatform extends PlatformPlugin { if (integrationTestDevice == null) { // Lazily instantiate compiler so it is built only if it is actually used. compiler ??= TestCompiler(debuggingOptions.buildInfo, flutterProject); - mainDart = await compiler.compile(globals.fs.file(mainDart).uri); + mainDart = await compiler!.compile(globals.fs.file(mainDart).uri); if (mainDart == null) { testHarnessChannel.sink.addError('Compilation failed for testPath=$testPath'); @@ -479,7 +479,7 @@ class FlutterPlatform extends PlatformPlugin { globals.printTrace('test $ourTestCount: starting test device'); final TestDevice testDevice = _createTestDevice(ourTestCount); - final Future> remoteChannelFuture = testDevice.start(mainDart); + final Future> remoteChannelFuture = testDevice.start(mainDart!); finalizers.add(() async { globals.printTrace('test $ourTestCount: ensuring test device is terminated.'); await testDevice.kill(); @@ -584,7 +584,7 @@ class FlutterPlatform extends PlatformPlugin { } String _generateTestMain({ - Uri testUrl, + required Uri testUrl, }) { assert(testUrl.scheme == 'file'); final File file = globals.fs.file(testUrl); @@ -592,14 +592,14 @@ class FlutterPlatform extends PlatformPlugin { final LanguageVersion languageVersion = determineLanguageVersion( file, - packageConfig[flutterProject?.manifest?.appName], - Cache.flutterRoot, + packageConfig[flutterProject!.manifest.appName], + Cache.flutterRoot!, ); return generateTestBootstrap( testUrl: testUrl, testConfigFile: findTestConfigFile(globals.fs.file(testUrl), globals.logger), - host: host, - updateGoldens: updateGoldens, + host: host!, + updateGoldens: updateGoldens!, flutterTestDep: packageConfig['flutter_test'] != null, languageVersionHeader: '// @dart=${languageVersion.major}.${languageVersion.minor}', integrationTest: _isIntegrationTest, @@ -609,7 +609,7 @@ class FlutterPlatform extends PlatformPlugin { @override Future close() async { if (compiler != null) { - await compiler.dispose(); + await compiler!.dispose(); compiler = null; } await _fontConfigManager.dispose(); @@ -633,7 +633,7 @@ class _FlutterPlatformStreamSinkWrapper implements StreamSink { _FlutterPlatformStreamSinkWrapper(this._parent, this._shellProcessClosed); final StreamSink _parent; - final Future<_AsyncError> _shellProcessClosed; + final Future<_AsyncError?> _shellProcessClosed; @override Future get done => _done.future; @@ -650,7 +650,7 @@ class _FlutterPlatformStreamSinkWrapper implements StreamSink { assert(futureResults.first == null); final dynamic lastResult = futureResults.last; if (lastResult is _AsyncError) { - _done.completeError(lastResult.error, lastResult.stack); + _done.completeError(lastResult.error as Object, lastResult.stack); } else { assert(lastResult == null); _done.complete(); @@ -664,7 +664,7 @@ class _FlutterPlatformStreamSinkWrapper implements StreamSink { @override void add(S event) => _parent.add(event); @override - void addError(dynamic errorEvent, [ StackTrace stackTrace ]) => _parent.addError(errorEvent, stackTrace); + void addError(Object errorEvent, [ StackTrace? stackTrace ]) => _parent.addError(errorEvent, stackTrace); @override Future addStream(Stream stream) => _parent.addStream(stream); } @@ -681,9 +681,9 @@ class _AsyncError { /// The returned future completes when either side is closed, which also /// indicates when the tests have finished. Future _pipeHarnessToRemote({ - @required int id, - @required StreamChannel harnessChannel, - @required StreamChannel remoteChannel, + required int id, + required StreamChannel harnessChannel, + required StreamChannel remoteChannel, }) async { globals.printTrace('test $id: Waiting for test harness or tests to finish'); diff --git a/packages/flutter_tools/lib/src/test/flutter_tester_device.dart b/packages/flutter_tools/lib/src/test/flutter_tester_device.dart index acf0de903cff..5d239fb2bc68 100644 --- a/packages/flutter_tools/lib/src/test/flutter_tester_device.dart +++ b/packages/flutter_tools/lib/src/test/flutter_tester_device.dart @@ -2,7 +2,7 @@ // 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 'dart:io' as io; // flutter_ignore: dart_io_import; @@ -29,25 +29,26 @@ import 'test_device.dart'; /// Implementation of [TestDevice] with the Flutter Tester over a [Process]. class FlutterTesterTestDevice extends TestDevice { FlutterTesterTestDevice({ - @required this.id, - @required this.platform, - @required this.fileSystem, - @required this.processManager, - @required this.logger, - @required this.shellPath, - @required this.debuggingOptions, - @required this.enableObservatory, - @required this.machine, - @required this.host, - @required this.testAssetDirectory, - @required this.flutterProject, - @required this.icudtlPath, - @required this.compileExpression, - @required this.fontConfigManager, + required this.id, + required this.platform, + required this.fileSystem, + required this.processManager, + required this.logger, + required this.shellPath, + required this.debuggingOptions, + required this.enableObservatory, + required this.machine, + required this.host, + required this.testAssetDirectory, + required this.flutterProject, + required this.icudtlPath, + required this.compileExpression, + required this.fontConfigManager, }) : assert(shellPath != null), // Please provide the path to the shell in the SKY_SHELL environment variable. assert(!debuggingOptions.startPaused || enableObservatory), _gotProcessObservatoryUri = enableObservatory - ? Completer() : (Completer()..complete(null)), + // ignore: null_argument_to_non_null_type + ? Completer() : (Completer()..complete()), _operatingSystemUtils = OperatingSystemUtils( fileSystem: fileSystem, logger: logger, @@ -64,19 +65,19 @@ class FlutterTesterTestDevice extends TestDevice { final String shellPath; final DebuggingOptions debuggingOptions; final bool enableObservatory; - final bool machine; - final InternetAddress host; - final String testAssetDirectory; - final FlutterProject flutterProject; - final String icudtlPath; - final CompileExpression compileExpression; + final bool? machine; + final InternetAddress? host; + final String? testAssetDirectory; + final FlutterProject? flutterProject; + final String? icudtlPath; + final CompileExpression? compileExpression; final FontConfigManager fontConfigManager; final Completer _gotProcessObservatoryUri; final Completer _exitCode = Completer(); - Process _process; - HttpServer _server; + Process? _process; + HttpServer? _server; final OperatingSystemUtils _operatingSystemUtils; /// Starts the device. @@ -92,7 +93,7 @@ class FlutterTesterTestDevice extends TestDevice { // Prepare our WebSocket server to talk to the engine subprocess. // Let the server choose an unused port. _server = await bind(host, /*port*/ 0); - logger.printTrace('test $id: test harness socket server is running at port:${_server.port}'); + logger.printTrace('test $id: test harness socket server is running at port:${_server!.port}'); final List command = [ // Until an arm64 flutter tester binary is available, force to run in Rosetta // to avoid "unexpectedly got a signal in sigtramp" crash. @@ -118,7 +119,7 @@ class FlutterTesterTestDevice extends TestDevice { ] else '--disable-observatory', - if (host.type == InternetAddressType.IPv6) '--ipv6', + if (host!.type == InternetAddressType.IPv6) '--ipv6', if (icudtlPath != null) '--icu-data-file-path=$icudtlPath', '--enable-checked-mode', '--verify-entry-points', @@ -143,38 +144,38 @@ class FlutterTesterTestDevice extends TestDevice { // If FLUTTER_TEST has not been set, assume from this context that this // call was invoked by the command 'flutter test'. final String flutterTest = platform.environment.containsKey('FLUTTER_TEST') - ? platform.environment['FLUTTER_TEST'] + ? platform.environment['FLUTTER_TEST']! : 'true'; final Map environment = { 'FLUTTER_TEST': flutterTest, 'FONTCONFIG_FILE': fontConfigManager.fontConfigFile.path, - 'SERVER_PORT': _server.port.toString(), - 'APP_NAME': flutterProject?.manifest?.appName ?? '', + 'SERVER_PORT': _server!.port.toString(), + 'APP_NAME': flutterProject?.manifest.appName ?? '', if (testAssetDirectory != null) - 'UNIT_TEST_ASSETS': testAssetDirectory, + 'UNIT_TEST_ASSETS': testAssetDirectory!, }; logger.printTrace('test $id: Starting flutter_tester process with command=$command, environment=$environment'); _process = await processManager.start(command, environment: environment); // Unawaited to update state. - unawaited(_process.exitCode.then((int exitCode) { - logger.printTrace('test $id: flutter_tester process at pid ${_process.pid} exited with code=$exitCode'); + unawaited(_process!.exitCode.then((int exitCode) { + logger.printTrace('test $id: flutter_tester process at pid ${_process!.pid} exited with code=$exitCode'); _exitCode.complete(exitCode); })); - logger.printTrace('test $id: Started flutter_tester process at pid ${_process.pid}'); + logger.printTrace('test $id: Started flutter_tester process at pid ${_process!.pid}'); // Pipe stdout and stderr from the subprocess to our printStatus console. // We also keep track of what observatory port the engine used, if any. _pipeStandardStreamsToConsole( - process: _process, + process: _process!, reportObservatoryUri: (Uri detectedUri) async { assert(!_gotProcessObservatoryUri.isCompleted); assert(debuggingOptions.hostVmServicePort == null || debuggingOptions.hostVmServicePort == detectedUri.port); - Uri forwardingUri; + Uri? forwardingUri; if (debuggingOptions.enableDds) { logger.printTrace('test $id: Starting Dart Development Service'); final DartDevelopmentService dds = await startDds(detectedUri); @@ -186,7 +187,7 @@ class FlutterTesterTestDevice extends TestDevice { logger.printTrace('Connecting to service protocol: $forwardingUri'); final Future localVmService = connectToVmService( - forwardingUri, + forwardingUri!, compileExpression: compileExpression, logger: logger, ); @@ -194,7 +195,7 @@ class FlutterTesterTestDevice extends TestDevice { logger.printTrace('test $id: Successfully connected to service protocol: $forwardingUri'); })); - if (debuggingOptions.startPaused && !machine) { + if (debuggingOptions.startPaused && !machine!) { logger.printStatus('The test process has been started.'); logger.printStatus('You can now connect to it using observatory. To connect, load the following Web site in your browser:'); logger.printStatus(' $forwardingUri'); @@ -244,7 +245,7 @@ class FlutterTesterTestDevice extends TestDevice { Uri get _ddsServiceUri { return Uri( scheme: 'http', - host: (host.type == InternetAddressType.IPv6 ? + host: (host!.type == InternetAddressType.IPv6 ? InternetAddress.loopbackIPv6 : InternetAddress.loopbackIPv4 ).host, @@ -259,7 +260,7 @@ class FlutterTesterTestDevice extends TestDevice { uri, serviceUri: _ddsServiceUri, enableAuthCodes: !debuggingOptions.disableServiceAuthCodes, - ipv6: host.type == InternetAddressType.IPv6, + ipv6: host!.type == InternetAddressType.IPv6, ); } @@ -268,7 +269,7 @@ class FlutterTesterTestDevice extends TestDevice { /// Only intended to be overridden in tests. @protected @visibleForTesting - Future bind(InternetAddress host, int port) => HttpServer.bind(host, port); + Future bind(InternetAddress? host, int port) => HttpServer.bind(host, port); @protected @visibleForTesting @@ -276,7 +277,7 @@ class FlutterTesterTestDevice extends TestDevice { assert(_server != null); try { - final HttpRequest firstRequest = await _server.first; + final HttpRequest firstRequest = await _server!.first; final WebSocket webSocket = await WebSocketTransformer.upgrade(firstRequest); return _webSocketToStreamChannel(webSocket); } on Exception catch (error, stackTrace) { @@ -287,14 +288,14 @@ class FlutterTesterTestDevice extends TestDevice { @override String toString() { final String status = _process != null - ? 'pid: ${_process.pid}, ${_exitCode.isCompleted ? 'exited' : 'running'}' + ? 'pid: ${_process!.pid}, ${_exitCode.isCompleted ? 'exited' : 'running'}' : 'not started'; return 'Flutter Tester ($status) for test $id'; } void _pipeStandardStreamsToConsole({ - @required Process process, - @required Future Function(Uri uri) reportObservatoryUri, + required Process process, + required Future Function(Uri uri) reportObservatoryUri, }) { for (final Stream> stream in >>[ process.stderr, @@ -307,10 +308,10 @@ class FlutterTesterTestDevice extends TestDevice { (String line) async { logger.printTrace('test $id: Shell: $line'); - final Match match = globals.kVMServiceMessageRegExp.firstMatch(line); + final Match? match = globals.kVMServiceMessageRegExp.firstMatch(line); if (match != null) { try { - final Uri uri = Uri.parse(match[1]); + final Uri uri = Uri.parse(match[1]!); if (reportObservatoryUri != null) { await reportObservatoryUri(uri); } @@ -357,7 +358,7 @@ StreamChannel _webSocketToStreamChannel(WebSocket webSocket) { .pipe(webSocket); webSocket // We're only communicating with string encoded JSON. - .map((dynamic message) => message as String) + .map((dynamic message) => message as String?) .pipe(controller.local.sink); return controller.foreign; diff --git a/packages/flutter_tools/lib/src/test/flutter_web_goldens.dart b/packages/flutter_tools/lib/src/test/flutter_web_goldens.dart index b5c3afaa0f86..74c37a786bb4 100644 --- a/packages/flutter_tools/lib/src/test/flutter_web_goldens.dart +++ b/packages/flutter_tools/lib/src/test/flutter_web_goldens.dart @@ -2,12 +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 'dart:async'; import 'dart:typed_data'; -import 'package:meta/meta.dart'; import 'package:process/process.dart'; import '../base/file_system.dart'; @@ -28,26 +25,26 @@ import 'test_config.dart'; class TestGoldenComparator { /// Creates a [TestGoldenComparator] instance. TestGoldenComparator(this.shellPath, this.compilerFactory, { - @required Logger logger, - @required FileSystem fileSystem, - @required ProcessManager processManager, - @required this.webRenderer, + required Logger logger, + required FileSystem fileSystem, + required ProcessManager? processManager, + required this.webRenderer, }) : tempDir = fileSystem.systemTempDirectory.createTempSync('flutter_web_platform.'), _logger = logger, _fileSystem = fileSystem, _processManager = processManager; - final String shellPath; + final String? shellPath; final Directory tempDir; final TestCompiler Function() compilerFactory; final Logger _logger; final FileSystem _fileSystem; - final ProcessManager _processManager; + final ProcessManager? _processManager; final WebRendererMode webRenderer; - TestCompiler _compiler; - TestGoldenComparatorProcess _previousComparator; - Uri _previousTestUri; + TestCompiler? _compiler; + TestGoldenComparatorProcess? _previousComparator; + Uri? _previousTestUri; Future close() async { tempDir.deleteSync(recursive: true); @@ -57,13 +54,16 @@ class TestGoldenComparator { /// Start golden comparator in a separate process. Start one file per test file /// to reduce the overhead of starting `flutter_tester`. - Future _processForTestFile(Uri testUri) async { + Future _processForTestFile(Uri testUri) async { if (testUri == _previousTestUri) { return _previousComparator; } final String bootstrap = TestGoldenComparatorProcess.generateBootstrap(_fileSystem.file(testUri), testUri, logger: _logger); - final Process process = await _startProcess(bootstrap); + final Process? process = await _startProcess(bootstrap); + if (process == null) { + return null; + } unawaited(_previousComparator?.close()); _previousComparator = TestGoldenComparatorProcess(process, logger: _logger); _previousTestUri = testUri; @@ -71,16 +71,19 @@ class TestGoldenComparator { return _previousComparator; } - Future _startProcess(String testBootstrap) async { + Future _startProcess(String testBootstrap) async { // Prepare the Dart file that will talk to us and start the test. final File listenerFile = (await tempDir.createTemp('listener')).childFile('listener.dart'); await listenerFile.writeAsString(testBootstrap); // Lazily create the compiler _compiler = _compiler ?? compilerFactory(); - final String output = await _compiler.compile(listenerFile.uri); + final String? output = await _compiler!.compile(listenerFile.uri); + if (output == null) { + return null; + } final List command = [ - shellPath, + shellPath!, '--disable-observatory', '--non-interactive', '--packages=${_fileSystem.path.join('.dart_tool', 'package_config.json')}', @@ -92,12 +95,12 @@ class TestGoldenComparator { 'FLUTTER_TEST_BROWSER': 'chrome', 'FLUTTER_WEB_RENDERER': webRenderer == WebRendererMode.html ? 'html' : 'canvaskit', }; - return _processManager.start(command, environment: environment); + return _processManager!.start(command, environment: environment); } - Future compareGoldens(Uri testUri, Uint8List bytes, Uri goldenKey, bool updateGoldens) async { + Future compareGoldens(Uri testUri, Uint8List bytes, Uri goldenKey, bool? updateGoldens) async { final File imageFile = await (await tempDir.createTemp('image')).childFile('image').writeAsBytes(bytes); - final TestGoldenComparatorProcess process = await _processForTestFile(testUri); + final TestGoldenComparatorProcess process = await (_processForTestFile(testUri) as FutureOr); process.sendCommand(imageFile, goldenKey, updateGoldens); final Map result = await process.getResponse(); @@ -105,7 +108,7 @@ class TestGoldenComparator { if (result == null) { return 'unknown error'; } else { - return (result['success'] as bool) ? null : ((result['message'] as String) ?? 'does not match'); + return (result['success'] as bool) ? null : ((result['message'] as String?) ?? 'does not match'); } } } @@ -114,7 +117,7 @@ class TestGoldenComparator { /// handles communication with the child process. class TestGoldenComparatorProcess { /// Creates a [TestGoldenComparatorProcess] backed by [process]. - TestGoldenComparatorProcess(this.process, {@required Logger logger}) : _logger = logger { + TestGoldenComparatorProcess(this.process, {required Logger logger}) : _logger = logger { // Pipe stdout and stderr to printTrace and printError. // Also parse stdout as a stream of JSON objects. streamIterator = StreamIterator>( @@ -138,14 +141,14 @@ class TestGoldenComparatorProcess { final Logger _logger; final Process process; - StreamIterator> streamIterator; + late StreamIterator> streamIterator; Future close() async { process.kill(); await process.exitCode; } - void sendCommand(File imageFile, Uri goldenKey, bool updateGoldens) { + void sendCommand(File imageFile, Uri? goldenKey, bool? updateGoldens) { final Object command = jsonEncode({ 'imageFile': imageFile.path, 'key': goldenKey.toString(), @@ -161,8 +164,8 @@ class TestGoldenComparatorProcess { return streamIterator.current; } - static String generateBootstrap(File testFile, Uri testUri, {@required Logger logger}) { - final File testConfigFile = findTestConfigFile(testFile, logger); + static String generateBootstrap(File testFile, Uri testUri, {required Logger logger}) { + final File? testConfigFile = findTestConfigFile(testFile, logger); // Generate comparator process for the file. return ''' import 'dart:convert'; // flutter_ignore: dart_convert_import diff --git a/packages/flutter_tools/lib/src/test/flutter_web_platform.dart b/packages/flutter_tools/lib/src/test/flutter_web_platform.dart index 0ea468628886..fc20e51fa7ad 100644 --- a/packages/flutter_tools/lib/src/test/flutter_web_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_web_platform.dart @@ -2,14 +2,11 @@ // 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 'dart:typed_data'; import 'package:async/async.dart'; import 'package:http_multi_server/http_multi_server.dart'; -import 'package:meta/meta.dart'; import 'package:package_config/package_config.dart'; import 'package:pool/pool.dart'; import 'package:process/process.dart'; @@ -41,19 +38,19 @@ import 'test_compiler.dart'; class FlutterWebPlatform extends PlatformPlugin { FlutterWebPlatform._(this._server, this._config, this._root, { - FlutterProject flutterProject, - String shellPath, + FlutterProject? flutterProject, + String? shellPath, this.updateGoldens, this.nullAssertions, - @required this.buildInfo, - @required this.webMemoryFS, - @required FileSystem fileSystem, - @required PackageConfig flutterToolPackageConfig, - @required ChromiumLauncher chromiumLauncher, - @required Logger logger, - @required Artifacts artifacts, - @required ProcessManager processManager, - @required Cache cache, + required this.buildInfo, + required this.webMemoryFS, + required FileSystem fileSystem, + required PackageConfig flutterToolPackageConfig, + required ChromiumLauncher chromiumLauncher, + required Logger logger, + required Artifacts? artifacts, + required ProcessManager processManager, + required Cache cache, }) : _fileSystem = fileSystem, _flutterToolPackageConfig = flutterToolPackageConfig, _chromiumLauncher = chromiumLauncher, @@ -63,7 +60,7 @@ class FlutterWebPlatform extends PlatformPlugin { final shelf.Cascade cascade = shelf.Cascade() .add(_webSocketHandler.handler) .add(createStaticHandler( - fileSystem.path.join(Cache.flutterRoot, 'packages', 'flutter_tools'), + fileSystem.path.join(Cache.flutterRoot!, 'packages', 'flutter_tools'), serveFilesOutsidePath: true, )) .add(_handleStaticArtifact) @@ -93,9 +90,9 @@ class FlutterWebPlatform extends PlatformPlugin { final PackageConfig _flutterToolPackageConfig; final ChromiumLauncher _chromiumLauncher; final Logger _logger; - final Artifacts _artifacts; - final bool updateGoldens; - final bool nullAssertions; + final Artifacts? _artifacts; + final bool? updateGoldens; + final bool? nullAssertions; final OneOffHandler _webSocketHandler = OneOffHandler(); final AsyncMemoizer _closeMemo = AsyncMemoizer(); final String _root; @@ -106,28 +103,28 @@ class FlutterWebPlatform extends PlatformPlugin { /// to lead to flaky tests. final Pool _suiteLock = Pool(1); - BrowserManager _browserManager; - TestGoldenComparator _testGoldenComparator; + BrowserManager? _browserManager; + late TestGoldenComparator _testGoldenComparator; static Future start(String root, { - FlutterProject flutterProject, - String shellPath, + FlutterProject? flutterProject, + String? shellPath, bool updateGoldens = false, bool pauseAfterLoad = false, bool nullAssertions = false, - @required BuildInfo buildInfo, - @required WebMemoryFS webMemoryFS, - @required FileSystem fileSystem, - @required Logger logger, - @required ChromiumLauncher chromiumLauncher, - @required Artifacts artifacts, - @required ProcessManager processManager, - @required Cache cache, + required BuildInfo buildInfo, + required WebMemoryFS webMemoryFS, + required FileSystem fileSystem, + required Logger logger, + required ChromiumLauncher chromiumLauncher, + required Artifacts? artifacts, + required ProcessManager processManager, + required Cache cache, }) async { final shelf_io.IOServer server = shelf_io.IOServer(await HttpMultiServer.loopback(0)); final PackageConfig packageConfig = await loadPackageConfigWithLogging( fileSystem.file(fileSystem.path.join( - Cache.flutterRoot, + Cache.flutterRoot!, 'packages', 'flutter_tools', '.dart_tool', @@ -158,7 +155,7 @@ class FlutterWebPlatform extends PlatformPlugin { bool get _closed => _closeMemo.hasRun; /// Uri of the test package. - Uri get testUri => _flutterToolPackageConfig['test'].packageUriRoot; + Uri get testUri => _flutterToolPackageConfig['test']!.packageUriRoot; WebRendererMode get _rendererMode { return buildInfo.dartDefines.contains('FLUTTER_WEB_USE_SKIA=true') @@ -178,7 +175,7 @@ class FlutterWebPlatform extends PlatformPlugin { /// The ahem text file. File get _ahem => _fileSystem.file(_fileSystem.path.join( - Cache.flutterRoot, + Cache.flutterRoot!, 'packages', 'flutter_tools', 'static', @@ -187,7 +184,7 @@ class FlutterWebPlatform extends PlatformPlugin { /// The require js binary. File get _requireJs => _fileSystem.file(_fileSystem.path.join( - _artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path, + _artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath).path, 'lib', 'dev_compiler', 'kernel', @@ -197,7 +194,7 @@ class FlutterWebPlatform extends PlatformPlugin { /// The ddc to dart stack trace mapper. File get _stackTraceMapper => _fileSystem.file(_fileSystem.path.join( - _artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path, + _artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath).path, 'lib', 'dev_compiler', 'web', @@ -205,10 +202,10 @@ class FlutterWebPlatform extends PlatformPlugin { )); File get _dartSdk => _fileSystem.file( - _artifacts.getHostArtifact(kDartSdkJsArtifactMap[_rendererMode][_nullSafetyMode])); + _artifacts!.getHostArtifact(kDartSdkJsArtifactMap[_rendererMode]![_nullSafetyMode]!)); File get _dartSdkSourcemaps => _fileSystem.file( - _artifacts.getHostArtifact(kDartSdkJsMapArtifactMap[_rendererMode][_nullSafetyMode])); + _artifacts!.getHostArtifact(kDartSdkJsMapArtifactMap[_rendererMode]![_nullSafetyMode]!)); /// The precompiled test javascript. File get _testDartJs => _fileSystem.file(_fileSystem.path.join( @@ -254,7 +251,7 @@ class FlutterWebPlatform extends PlatformPlugin { final String leadingPath = request.url.path.split('.dart.bootstrap.js')[0]; final String generatedFile = '${_fileSystem.path.split(leadingPath).join('_')}.dart.test.dart.js'; return shelf.Response.ok(generateMainModule( - nullAssertions: nullAssertions, + nullAssertions: nullAssertions!, nativeNullAssertions: true, bootstrapModule: '${_fileSystem.path.basename(leadingPath)}.dart.bootstrap', entrypoint: '/$generatedFile' @@ -317,7 +314,7 @@ class FlutterWebPlatform extends PlatformPlugin { FutureOr _packageFilesHandler(shelf.Request request) async { if (request.requestedUri.pathSegments.first == 'packages') { - final Uri fileUri = buildInfo.packageConfig.resolve(Uri( + final Uri? fileUri = buildInfo.packageConfig.resolve(Uri( scheme: 'package', pathSegments: request.requestedUri.pathSegments.skip(1), )); @@ -344,16 +341,16 @@ class FlutterWebPlatform extends PlatformPlugin { Future _goldenFileHandler(shelf.Request request) async { if (request.url.path.contains('flutter_goldens')) { final Map body = json.decode(await request.readAsString()) as Map; - final Uri goldenKey = Uri.parse(body['key'] as String); - final Uri testUri = Uri.parse(body['testUri'] as String); - final num width = body['width'] as num; - final num height = body['height'] as num; + final Uri goldenKey = Uri.parse(body['key']! as String); + final Uri testUri = Uri.parse(body['testUri']! as String); + final num width = body['width']! as num; + final num height = body['height']! as num; Uint8List bytes; try { - final ChromeTab chromeTab = await _browserManager._browser.chromeConnection.getTab((ChromeTab tab) { - return tab.url.contains(_browserManager._browser.url); - }); + final ChromeTab chromeTab = await (_browserManager!._browser.chromeConnection.getTab((ChromeTab tab) { + return tab.url.contains(_browserManager!._browser.url!); + }) as FutureOr); final WipConnection connection = await chromeTab.connect(); final WipResponse response = await connection.sendCommand('Page.captureScreenshot', { // Clip the screenshot to include only the element. @@ -369,7 +366,7 @@ class FlutterWebPlatform extends PlatformPlugin { 'scale': 1.0, }, }); - bytes = base64.decode(response.result['data'] as String); + bytes = base64.decode(response.result!['data'] as String); } on WipError catch (ex) { _logger.printError('Caught WIPError: $ex'); return shelf.Response.ok('WIP error: $ex'); @@ -382,7 +379,7 @@ class FlutterWebPlatform extends PlatformPlugin { return shelf.Response.ok('Unknown error, bytes is null'); } - final String errorMessage = await _testGoldenComparator.compareGoldens(testUri, bytes, goldenKey, updateGoldens); + final String? errorMessage = await _testGoldenComparator.compareGoldens(testUri, bytes, goldenKey, updateGoldens); return shelf.Response.ok(errorMessage ?? 'true'); } else { return shelf.Response.notFound('Not Found'); @@ -473,8 +470,8 @@ class FlutterWebPlatform extends PlatformPlugin { final String pathFromTest = _fileSystem.path.relative(path, from: _fileSystem.path.join(_root, 'test')); final Uri suiteUrl = url.resolveUri(_fileSystem.path.toUri('${_fileSystem.path.withoutExtension(pathFromTest)}.html')); final String relativePath = _fileSystem.path.relative(_fileSystem.path.normalize(path), from: _fileSystem.currentDirectory.path); - final RunnerSuite suite = await _browserManager.load(relativePath, suiteUrl, suiteConfig, message, onDone: () async { - await _browserManager.close(); + final RunnerSuite suite = await _browserManager!.load(relativePath, suiteUrl, suiteConfig, message, onDone: () async { + await _browserManager!.close(); _browserManager = null; lockResource.release(); }); @@ -516,7 +513,7 @@ class FlutterWebPlatform extends PlatformPlugin { @override Future closeEphemeral() async { if (_browserManager != null) { - await _browserManager.close(); + await _browserManager!.close(); } } @@ -524,7 +521,7 @@ class FlutterWebPlatform extends PlatformPlugin { Future close() => _closeMemo.runOnce(() async { await Future.wait(>[ if (_browserManager != null) - _browserManager.close(), + _browserManager!.close(), _server.close(), _testGoldenComparator.close(), ]); @@ -561,7 +558,7 @@ class OneOffHandler { return shelf.Response.notFound(null); } final String path = components.removeAt(0); - final FutureOr Function(shelf.Request) handler = + final FutureOr Function(shelf.Request)? handler = _handlers.remove(path); if (handler == null) { return shelf.Response.notFound(null); @@ -590,8 +587,8 @@ class BrowserManager { // Whenever we get a message, no matter which child channel it's for, we know // the browser is still running code which means the user isn't debugging. _channel = MultiChannel( - webSocket.cast().transform(jsonDocument).changeStream((Stream stream) { - return stream.map((Object message) { + webSocket.cast().transform(jsonDocument).changeStream((Stream stream) { + return stream.map((Object? message) { if (!_closed) { _timer.reset(); } @@ -615,7 +612,7 @@ class BrowserManager { /// The channel used to communicate with the browser. /// /// This is connected to a page running `static/host.dart`. - MultiChannel _channel; + late MultiChannel _channel; /// The ID of the next suite to be loaded. /// @@ -630,14 +627,14 @@ class BrowserManager { /// /// This will be `null` as long as the browser isn't displaying a pause /// screen. - CancelableCompleter _pauseCompleter; + CancelableCompleter? _pauseCompleter; /// The controller for [_BrowserEnvironment.onRestart]. final StreamController _onRestartController = StreamController.broadcast(); /// The environment to attach to each suite. - Future<_BrowserEnvironment> _environment; + late Future<_BrowserEnvironment> _environment; /// Controllers for every suite in this browser. /// @@ -649,7 +646,7 @@ class BrowserManager { // // Because the browser stops running code when the user is actively debugging, // this lets us detect whether they're debugging reasonably accurately. - RestartableTimer _timer; + late RestartableTimer _timer; final AsyncMemoizer _closeMemoizer = AsyncMemoizer(); @@ -677,25 +674,23 @@ class BrowserManager { final Chromium chrome = await chromiumLauncher.launch(url.toString(), headless: headless); final Completer completer = Completer(); - unawaited(chrome.onExit.then((int browserExitCode) { + unawaited(chrome.onExit.then((int? browserExitCode) { throwToolExit('${runtime.name} exited with code $browserExitCode before connecting.'); - }).catchError((dynamic error, StackTrace stackTrace) { - if (completer.isCompleted) { - return null; + }).catchError((Object error, StackTrace stackTrace) { + if (!completer.isCompleted) { + completer.completeError(error, stackTrace); } - completer.completeError(error, stackTrace); })); unawaited(future.then((WebSocketChannel webSocket) { if (completer.isCompleted) { return; } completer.complete(BrowserManager._(chrome, runtime, webSocket)); - }).catchError((dynamic error, StackTrace stackTrace) { + }).catchError((Object error, StackTrace stackTrace) { chrome.close(); - if (completer.isCompleted) { - return null; + if (!completer.isCompleted) { + completer.completeError(error, stackTrace); } - completer.completeError(error, stackTrace); })); return completer.future; @@ -720,7 +715,7 @@ class BrowserManager { Uri url, SuiteConfiguration suiteConfig, Object message, { - Future Function() onDone, + Future Function()? onDone, } ) async { url = url.replace(fragment: Uri.encodeFull(jsonEncode({ @@ -729,7 +724,7 @@ class BrowserManager { }))); final int suiteID = _suiteID++; - RunnerSuiteController controller; + RunnerSuiteController? controller; void closeIframe() { if (_closed) { return; @@ -747,7 +742,7 @@ class BrowserManager { StreamTransformer.fromHandlers(handleDone: (EventSink sink) { closeIframe(); sink.close(); - onDone(); + onDone!(); }), ); @@ -774,25 +769,25 @@ class BrowserManager { /// An implementation of [Environment.displayPause]. CancelableOperation _displayPause() { if (_pauseCompleter != null) { - return _pauseCompleter.operation; + return _pauseCompleter!.operation; } _pauseCompleter = CancelableCompleter(onCancel: () { _channel.sink.add({'command': 'resume'}); _pauseCompleter = null; }); - _pauseCompleter.operation.value.whenComplete(() { + _pauseCompleter!.operation.value.whenComplete(() { _pauseCompleter = null; }); _channel.sink.add({'command': 'displayPause'}); - return _pauseCompleter.operation; + return _pauseCompleter!.operation; } /// The callback for handling messages received from the host page. void _onMessage(dynamic message) { assert(message is Map); if (message is Map) { - switch (message['command'] as String) { + switch (message['command'] as String?) { case 'ping': break; case 'restart': @@ -800,7 +795,7 @@ class BrowserManager { break; case 'resume': if (_pauseCompleter != null) { - _pauseCompleter.complete(); + _pauseCompleter!.complete(); } break; default: @@ -818,7 +813,7 @@ class BrowserManager { _closed = true; _timer.cancel(); if (_pauseCompleter != null) { - _pauseCompleter.complete(); + _pauseCompleter!.complete(); } _pauseCompleter = null; _controllers.clear(); @@ -844,7 +839,7 @@ class _BrowserEnvironment implements Environment { final bool supportsDebugging = true; @override - final Uri observatoryUrl; + final Uri? observatoryUrl; @override final Uri remoteDebuggerUrl; diff --git a/packages/flutter_tools/lib/src/test/integration_test_device.dart b/packages/flutter_tools/lib/src/test/integration_test_device.dart index 002290eb71b2..c95db3774899 100644 --- a/packages/flutter_tools/lib/src/test/integration_test_device.dart +++ b/packages/flutter_tools/lib/src/test/integration_test_device.dart @@ -29,7 +29,7 @@ class IntegrationTestTestDevice implements TestDevice { final int id; final Device device; final DebuggingOptions debuggingOptions; - final String userIdentifier; + final String? userIdentifier; ApplicationPackage? _applicationPackage; final Completer _finished = Completer(); @@ -50,7 +50,7 @@ class IntegrationTestTestDevice implements TestDevice { } final LaunchResult launchResult = await device.startApp( - _applicationPackage!, + _applicationPackage, mainPath: entrypointPath, platformArgs: {}, debuggingOptions: debuggingOptions, diff --git a/packages/flutter_tools/lib/src/test/runner.dart b/packages/flutter_tools/lib/src/test/runner.dart index 0de204e8ea20..0ebf9e9e9796 100644 --- a/packages/flutter_tools/lib/src/test/runner.dart +++ b/packages/flutter_tools/lib/src/test/runner.dart @@ -2,10 +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:meta/meta.dart'; - import '../artifacts.dart'; import '../base/common.dart'; import '../base/file_system.dart'; @@ -29,32 +25,32 @@ abstract class FlutterTestRunner { Future runTests( TestWrapper testWrapper, List testFiles, { - @required DebuggingOptions debuggingOptions, + required DebuggingOptions debuggingOptions, List names = const [], List plainNames = const [], - String tags, - String excludeTags, + String? tags, + String? excludeTags, bool enableObservatory = false, bool ipv6 = false, bool machine = false, - String precompiledDillPath, - Map precompiledDillFiles, + String? precompiledDillPath, + Map? precompiledDillFiles, bool updateGoldens = false, - TestWatcher watcher, - @required int concurrency, - String testAssetDirectory, - FlutterProject flutterProject, - String icudtlPath, - Directory coverageDirectory, + TestWatcher? watcher, + required int? concurrency, + String? testAssetDirectory, + FlutterProject? flutterProject, + String? icudtlPath, + Directory? coverageDirectory, bool web = false, - String randomSeed, - String reporter, - String timeout, + String? randomSeed, + String? reporter, + String? timeout, bool runSkipped = false, - int shardIndex, - int totalShards, - Device integrationTestDevice, - String integrationTestUserIdentifier, + int? shardIndex, + int? totalShards, + Device? integrationTestDevice, + String? integrationTestUserIdentifier, }); } @@ -65,35 +61,35 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner { Future runTests( TestWrapper testWrapper, List testFiles, { - @required DebuggingOptions debuggingOptions, + required DebuggingOptions debuggingOptions, List names = const [], List plainNames = const [], - String tags, - String excludeTags, + String? tags, + String? excludeTags, bool enableObservatory = false, bool ipv6 = false, bool machine = false, - String precompiledDillPath, - Map precompiledDillFiles, + String? precompiledDillPath, + Map? precompiledDillFiles, bool updateGoldens = false, - TestWatcher watcher, - @required int concurrency, - String testAssetDirectory, - FlutterProject flutterProject, - String icudtlPath, - Directory coverageDirectory, + TestWatcher? watcher, + required int? concurrency, + String? testAssetDirectory, + FlutterProject? flutterProject, + String? icudtlPath, + Directory? coverageDirectory, bool web = false, - String randomSeed, - String reporter, - String timeout, + String? randomSeed, + String? reporter, + String? timeout, bool runSkipped = false, - int shardIndex, - int totalShards, - Device integrationTestDevice, - String integrationTestUserIdentifier, + int? shardIndex, + int? totalShards, + Device? integrationTestDevice, + String? integrationTestUserIdentifier, }) async { // Configure package:test to use the Flutter engine for child processes. - final String shellPath = globals.artifacts.getArtifactPath(Artifact.flutterTester); + final String shellPath = globals.artifacts!.getArtifactPath(Artifact.flutterTester); // Compute the command-line arguments for package:test. final List testArgs = [ @@ -136,11 +132,11 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner { logger: globals.logger, fileSystem: globals.fs, platform: globals.platform, - artifacts: globals.artifacts, + artifacts: globals.artifacts!, processManager: globals.processManager, config: globals.config, ).initialize( - projectDirectory: flutterProject.directory, + projectDirectory: flutterProject!.directory, testOutputDir: tempBuildDir, testFiles: testFiles, buildInfo: debuggingOptions.buildInfo, diff --git a/packages/flutter_tools/lib/src/test/test_compiler.dart b/packages/flutter_tools/lib/src/test/test_compiler.dart index 66b60b4b16ee..8f9d4ea8dae2 100644 --- a/packages/flutter_tools/lib/src/test/test_compiler.dart +++ b/packages/flutter_tools/lib/src/test/test_compiler.dart @@ -2,7 +2,7 @@ // 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'; @@ -22,7 +22,7 @@ class CompilationRequest { CompilationRequest(this.mainUri, this.result); Uri mainUri; - Completer result; + Completer result; } /// A frontend_server wrapper for the flutter test runner. @@ -43,9 +43,9 @@ class TestCompiler { TestCompiler( this.buildInfo, this.flutterProject, - { String precompiledDillPath } + { String? precompiledDillPath } ) : testFilePath = precompiledDillPath ?? globals.fs.path.join( - flutterProject.directory.path, + flutterProject!.directory.path, getBuildDirectory(), 'test_cache', getDefaultCachedKernelPath( @@ -69,19 +69,19 @@ class TestCompiler { final StreamController compilerController = StreamController(); final List compilationQueue = []; - final FlutterProject flutterProject; + final FlutterProject? flutterProject; final BuildInfo buildInfo; final String testFilePath; final bool shouldCopyDillFile; - ResidentCompiler compiler; - File outputDill; + ResidentCompiler? compiler; + late File outputDill; - Future compile(Uri mainDart) { + Future compile(Uri mainDart) { final Completer completer = Completer(); if (compilerController.isClosed) { - return Future.value(); + return Future.value(); } compilerController.add(CompilationRequest(mainDart, completer)); return completer.future; @@ -91,7 +91,7 @@ class TestCompiler { // Check for null in case this instance is shut down before the // lazily-created compiler has been created. if (compiler != null) { - await compiler.shutdown(); + await compiler!.shutdown(); compiler = null; } } @@ -103,10 +103,10 @@ class TestCompiler { /// Create the resident compiler used to compile the test. @visibleForTesting - Future createCompiler() async { + Future createCompiler() async { final ResidentCompiler residentCompiler = ResidentCompiler( - globals.artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), - artifacts: globals.artifacts, + globals.artifacts!.getArtifactPath(Artifact.flutterPatchedSdkPath), + artifacts: globals.artifacts!, logger: globals.logger, processManager: globals.processManager, buildMode: buildInfo.mode, @@ -151,31 +151,30 @@ class TestCompiler { final String mainUriString = buildInfo.packageConfig.toPackageUri(request.mainUri)?.toString() ?? request.mainUri.toString(); await generateMainDartWithPluginRegistrant( - flutterProject, + flutterProject!, buildInfo.packageConfig, mainUriString, globals.fs.file(request.mainUri), - throwOnPluginPubspecError: false, ); - invalidatedRegistrantFiles.add(flutterProject.dartPluginRegistrant.absolute.uri); + invalidatedRegistrantFiles.add(flutterProject!.dartPluginRegistrant.absolute.uri); } - final CompilerOutput compilerOutput = await compiler.recompile( + final CompilerOutput? compilerOutput = await compiler!.recompile( request.mainUri, [request.mainUri, ...invalidatedRegistrantFiles], outputPath: outputDill.path, packageConfig: buildInfo.packageConfig, - projectRootPath: flutterProject?.directory?.absolute?.path, + projectRootPath: flutterProject?.directory.absolute.path, checkDartPluginRegistry: true, fs: globals.fs, ); - final String outputPath = compilerOutput?.outputFilename; + final String? outputPath = compilerOutput?.outputFilename; // In case compiler didn't produce output or reported compilation // errors, pass [null] upwards to the consumer and shutdown the // compiler to avoid reusing compiler that might have gotten into // a weird state. - if (outputPath == null || compilerOutput.errorCount > 0) { + if (outputPath == null || compilerOutput!.errorCount > 0) { request.result.complete(null); await _shutdown(); } else { @@ -197,8 +196,8 @@ class TestCompiler { } else { request.result.complete(outputPath); } - compiler.accept(); - compiler.reset(); + compiler!.accept(); + compiler!.reset(); } globals.printTrace('Compiling ${request.mainUri} took ${compilerTime.elapsedMilliseconds}ms'); // Only remove now when we finished processing the element diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index 2a34556d42ad..4abc7054054d 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -99,7 +99,7 @@ typedef CompileExpression = Future Function( /// A method that pulls an SkSL shader from the device and writes it to a file. /// /// The name of the file returned as a result. -typedef GetSkSLMethod = Future Function(); +typedef GetSkSLMethod = Future Function(); Future _defaultOpenChannel(String url, { io.CompressionOptions compression = io.CompressionOptions.compressionDefault, @@ -265,7 +265,14 @@ Future setUpVmService( } if (skSLMethod != null) { vmService.registerServiceCallback('flutterGetSkSL', (Map params) async { - final String filename = await skSLMethod(); + final String? filename = await skSLMethod(); + if (filename == null) { + return { + 'result': { + 'type': 'Success', + }, + }; + } return { 'result': { 'type': 'Success', diff --git a/packages/flutter_tools/lib/src/web/web_runner.dart b/packages/flutter_tools/lib/src/web/web_runner.dart index 2c3a92e7a38e..3094ac7a7245 100644 --- a/packages/flutter_tools/lib/src/web/web_runner.dart +++ b/packages/flutter_tools/lib/src/web/web_runner.dart @@ -2,10 +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:meta/meta.dart'; - import '../base/context.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; @@ -16,7 +12,7 @@ import '../project.dart'; import '../reporting/reporting.dart'; import '../resident_runner.dart'; -WebRunnerFactory get webRunnerFactory => context.get(); +WebRunnerFactory? get webRunnerFactory => context.get(); // Hack to hide web imports for google3. abstract class WebRunnerFactory { @@ -25,16 +21,16 @@ abstract class WebRunnerFactory { /// Create a [ResidentRunner] for the web. ResidentRunner createWebRunner( FlutterDevice device, { - String target, - @required bool stayResident, - @required FlutterProject flutterProject, - @required bool ipv6, - @required DebuggingOptions debuggingOptions, - @required UrlTunneller urlTunneller, - @required Logger logger, - @required FileSystem fileSystem, - @required SystemClock systemClock, - @required Usage usage, + String? target, + required bool stayResident, + required FlutterProject flutterProject, + required bool? ipv6, + required DebuggingOptions debuggingOptions, + required UrlTunneller? urlTunneller, + required Logger? logger, + required FileSystem fileSystem, + required SystemClock systemClock, + required Usage usage, bool machine = false, }); } diff --git a/packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart b/packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart index 38b8b0daa7e9..4527d9d3eec7 100644 --- a/packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart +++ b/packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart @@ -173,14 +173,6 @@ void main() { await device.start('example.dill'); expect(processManager.hasRemainingExpectations, isFalse); }); - - testUsingContext('as null when set to null', () async { - platform.environment = {'FLUTTER_TEST': null}; - processManager.addCommand(flutterTestCommand(null)); - - await device.start('example.dill'); - expect(processManager.hasRemainingExpectations, isFalse); - }); }); group('Dart Entrypoint Args', () { diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart index c5af97d51ddc..88e7007562a7 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart @@ -52,7 +52,6 @@ void main() { flutterProject: project, debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), systemClock: SystemClock.fixed(DateTime(0, 0, 0)), @@ -80,7 +79,6 @@ void main() { flutterProject: project, debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), systemClock: SystemClock.fixed(DateTime(0, 0, 0)), @@ -103,7 +101,6 @@ void main() { flutterProject: project, debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), systemClock: SystemClock.fixed(DateTime(0, 0, 0)), @@ -125,7 +122,6 @@ void main() { flutterProject: project, debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), systemClock: SystemClock.fixed(DateTime(0, 0, 0)), @@ -152,7 +148,6 @@ void main() { flutterProject: project, debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), systemClock: SystemClock.fixed(DateTime(0, 0, 0)), diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index cfdfa8b7e2a4..00f08a257f3b 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -159,7 +159,6 @@ void main() { flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), usage: globals.flutterUsage, @@ -188,7 +187,6 @@ void main() { flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, startPaused: true), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), usage: globals.flutterUsage, @@ -207,7 +205,6 @@ void main() { flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), usage: globals.flutterUsage, @@ -220,7 +217,6 @@ void main() { flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), usage: globals.flutterUsage, @@ -322,7 +318,6 @@ void main() { debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), ipv6: true, stayResident: false, - urlTunneller: null, fileSystem: fileSystem, logger: logger, usage: globals.flutterUsage, @@ -346,7 +341,6 @@ void main() { debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), ipv6: true, stayResident: false, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), usage: globals.flutterUsage, @@ -463,7 +457,6 @@ void main() { flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, startPaused: true), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: BufferLogger.test(), usage: globals.flutterUsage, @@ -789,6 +782,7 @@ void main() { testUsingContext('cleanup of resources is safe to call multiple times', () async { final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); + mockDevice.dds = DartDevelopmentService(); fakeVmServiceHost = FakeVmServiceHost(requests: [ ...kAttachExpectations, ]); @@ -882,7 +876,6 @@ void main() { flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: logger, usage: globals.flutterUsage, @@ -925,7 +918,6 @@ void main() { flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), ipv6: true, - urlTunneller: null, fileSystem: fileSystem, logger: logger, usage: globals.flutterUsage, @@ -1075,7 +1067,6 @@ ResidentRunner setUpResidentRunner(FlutterDevice flutterDevice, { flutterProject: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory), debuggingOptions: debuggingOptions ?? DebuggingOptions.enabled(BuildInfo.debug), ipv6: true, - urlTunneller: null, usage: globals.flutterUsage, systemClock: systemClock ?? SystemClock.fixed(DateTime.now()), fileSystem: globals.fs, diff --git a/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart b/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart index fa927373b656..c6afde1ea3e7 100644 --- a/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart +++ b/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart @@ -4,6 +4,8 @@ // @dart = 2.8 +// ignore_for_file: avoid_redundant_argument_values + import 'dart:io' hide Directory, File; import 'package:flutter_tools/src/artifacts.dart'; diff --git a/packages/flutter_tools/test/src/fake_vm_services.dart b/packages/flutter_tools/test/src/fake_vm_services.dart index 08c20160cedb..09e6931e9ae1 100644 --- a/packages/flutter_tools/test/src/fake_vm_services.dart +++ b/packages/flutter_tools/test/src/fake_vm_services.dart @@ -93,7 +93,7 @@ abstract class VmServiceExpectation { class FakeVmServiceRequest implements VmServiceExpectation { const FakeVmServiceRequest({ required this.method, - this.args = const {}, + this.args = const {}, this.jsonResponse, this.errorCode, this.close = false, @@ -107,7 +107,7 @@ class FakeVmServiceRequest implements VmServiceExpectation { /// If non-null, the error code for a [vm_service.RPCError] in place of a /// standard response. final int? errorCode; - final Map? args; + final Map? args; final Map? jsonResponse; @override