diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index b1792259a7..065456e84f 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -500,10 +500,11 @@ abstract class ScrollableState extends State { return fling(scrollVelocity.clamp(-kMaxFlingVelocity, kMaxFlingVelocity)).then(_endScroll); } - void _endScroll([_]) { + Null _endScroll([Null _]) { _numberOfInProgressScrolls -= 1; if (_numberOfInProgressScrolls == 0) dispatchOnScrollEnd(); + return null; } /// Calls the dispatchOnScrollEnd callback. diff --git a/packages/flutter_driver/lib/src/driver.dart b/packages/flutter_driver/lib/src/driver.dart index 39625af8c6..9ec366b685 100644 --- a/packages/flutter_driver/lib/src/driver.dart +++ b/packages/flutter_driver/lib/src/driver.dart @@ -64,7 +64,7 @@ class FlutterDriver { // Attempts to resume the isolate, but does not crash if it fails because // the isolate is already resumed. There could be a race with other tools, // such as a debugger, any of which could have resumed the isolate. - Future resumeLeniently() { + Future resumeLeniently() { _log.trace('Attempting to resume isolate'); return isolate.resume().catchError((dynamic e) { const int vmMustBePausedCode = 101; @@ -87,7 +87,7 @@ class FlutterDriver { _log.trace('Isolate is paused at start.'); // Waits for a signal from the VM service that the extension is registered - Future waitForServiceExtension() { + Future waitForServiceExtension() { return isolate.onExtensionAdded.firstWhere((String extension) { return extension == _kFlutterExtensionMethod; }); @@ -96,8 +96,8 @@ class FlutterDriver { // If the isolate is paused at the start, e.g. via the --start-paused // option, then the VM service extension is not registered yet. Wait for // it to be registered. - Future whenResumed = resumeLeniently(); - Future whenServiceExtensionReady = Future.any(>[ + Future whenResumed = resumeLeniently(); + Future whenServiceExtensionReady = Future.any/*dynamic*/(>[ waitForServiceExtension(), // We will never receive the extension event if the user does not // register it. If that happens time out. @@ -180,7 +180,7 @@ class FlutterDriver { } Future tap(ObjectRef ref) async { - return await _sendCommand(new Tap(ref)).then((_) => null); + return await _sendCommand(new Tap(ref)).then((Map _) => null); } /// Tell the driver to perform a scrolling action. @@ -197,7 +197,7 @@ class FlutterDriver { /// The move events are generated at a given [frequency] in Hz (or events per /// second). It defaults to 60Hz. Future scroll(ObjectRef ref, double dx, double dy, Duration duration, {int frequency: 60}) async { - return await _sendCommand(new Scroll(ref, dx, dy, duration, frequency)).then((_) => null); + return await _sendCommand(new Scroll(ref, dx, dy, duration, frequency)).then((Map _) => null); } Future getText(ObjectRef ref) async { diff --git a/packages/flutter_driver/test/flutter_driver_test.dart b/packages/flutter_driver/test/flutter_driver_test.dart index 3d7c118f68..466daf4c08 100644 --- a/packages/flutter_driver/test/flutter_driver_test.dart +++ b/packages/flutter_driver/test/flutter_driver_test.dart @@ -16,13 +16,13 @@ import 'package:vm_service_client/vm_service_client.dart'; void main() { group('FlutterDriver.connect', () { List log; - StreamSubscription logSub; + StreamSubscription logSub; MockVMServiceClient mockClient; MockVM mockVM; MockIsolate mockIsolate; void expectLogContains(String message) { - expect(log.map((r) => '$r'), anyElement(contains(message))); + expect(log.map((LogRecord r) => '$r'), anyElement(contains(message))); } setUp(() { @@ -35,8 +35,8 @@ void main() { when(mockVM.isolates).thenReturn([mockIsolate]); when(mockIsolate.loadRunnable()).thenReturn(mockIsolate); when(mockIsolate.invokeExtension(any, any)) - .thenReturn(new Future.value({'status': 'ok'})); - vmServiceConnectFunction = (_) => new Future.value(mockClient); + .thenReturn(new Future>.value({'status': 'ok'})); + vmServiceConnectFunction = (String url) => new Future.value(mockClient); }); tearDown(() async { @@ -46,9 +46,8 @@ void main() { test('connects to isolate paused at start', () async { when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseStartEvent()); - when(mockIsolate.resume()).thenReturn(new Future.value()); - when(mockIsolate.onExtensionAdded) - .thenReturn(new Stream.fromIterable(['ext.flutter_driver'])); + when(mockIsolate.resume()).thenReturn(new Future.value()); + when(mockIsolate.onExtensionAdded).thenReturn(new Stream.fromIterable(['ext.flutter_driver'])); FlutterDriver driver = await FlutterDriver.connect(); expect(driver, isNotNull); @@ -57,7 +56,7 @@ void main() { test('connects to isolate paused mid-flight', () async { when(mockIsolate.pauseEvent).thenReturn(new MockVMPauseBreakpointEvent()); - when(mockIsolate.resume()).thenReturn(new Future.value()); + when(mockIsolate.resume()).thenReturn(new Future.value()); FlutterDriver driver = await FlutterDriver.connect(); expect(driver, isNotNull); @@ -73,7 +72,7 @@ void main() { when(mockIsolate.resume()).thenAnswer((_) { // This needs to be wrapped in a closure to not be considered uncaught // by package:test - return new Future.error(new rpc.RpcException(101, '')); + return new Future.error(new rpc.RpcException(101, '')); }); FlutterDriver driver = await FlutterDriver.connect(); @@ -101,7 +100,7 @@ void main() { }); test('checks the health of the driver extension', () async { - when(mockIsolate.invokeExtension(any, any)).thenReturn(new Future.value({ + when(mockIsolate.invokeExtension(any, any)).thenReturn(new Future>.value({ 'status': 'ok', })); Health result = await driver.checkHealth(); @@ -109,7 +108,7 @@ void main() { }); test('closes connection', () async { - when(mockClient.close()).thenReturn(new Future.value()); + when(mockClient.close()).thenReturn(new Future.value()); await driver.close(); }); @@ -127,7 +126,7 @@ void main() { 'keyValueString': 'foo', 'keyValueType': 'String' }); - return new Future.value({ + return new Future>.value({ 'objectReferenceKey': '123', }); }); @@ -149,11 +148,11 @@ void main() { test('sends the tap command', () async { when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { - expect(i.positionalArguments[1], { + expect(i.positionalArguments[1], { 'command': 'tap', 'targetRef': '123' }); - return new Future.value(); + return new Future>.value(); }); await driver.tap(new ObjectRef('123')); }); @@ -171,11 +170,11 @@ void main() { test('sends the getText command', () async { when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { - expect(i.positionalArguments[1], { + expect(i.positionalArguments[1], { 'command': 'get_text', 'targetRef': '123' }); - return new Future.value({ + return new Future>.value({ 'text': 'hello' }); }); @@ -188,7 +187,7 @@ void main() { test('waits for a condition', () { expect( driver.waitFor(() { - return new Future.delayed( + return new Future.delayed( new Duration(milliseconds: 50), () => 123 ); @@ -228,7 +227,7 @@ void main() { equals(2), timeout: new Duration(milliseconds: 10), pauseBetweenRetries: new Duration(milliseconds: 2) - ).catchError((err, stack) { + ).catchError((dynamic err, dynamic stack) { timedOut = true; }); diff --git a/packages/flutter_driver/test/retry_test.dart b/packages/flutter_driver/test/retry_test.dart index b4fa3fd424..c188d1aa3d 100644 --- a/packages/flutter_driver/test/retry_test.dart +++ b/packages/flutter_driver/test/retry_test.dart @@ -62,7 +62,7 @@ void main() { () async => retryCount++, new Duration(milliseconds: 30), new Duration(milliseconds: 10), - predicate: (value) => value == 2 + predicate: (int value) => value == 2 ), completion(2) ); @@ -85,7 +85,7 @@ void main() { }, new Duration(milliseconds: 7), new Duration(milliseconds: 2) - ).catchError((error, stackTrace) { + ).catchError((dynamic error, dynamic stackTrace) { timedOut = true; lastError = error; lastStackTrace = stackTrace; diff --git a/packages/flutter_tools/.analysis_options b/packages/flutter_tools/.analysis_options index 9be1748056..fb5be33999 100644 --- a/packages/flutter_tools/.analysis_options +++ b/packages/flutter_tools/.analysis_options @@ -16,14 +16,13 @@ analyzer: strong_mode_static_type_error: ignore strong_mode_down_cast_composite: ignore type_argument_not_matching_bounds: ignore - argument_type_not_assignable: ignore # we allow having TODOs in the code todo: ignore linter: rules: - avoid_empty_else - always_declare_return_types - # - always_specify_types # still a lot of work to do before enabling this one + - always_specify_types # - annotate_overrides # still a lot of work to do before enabling this one # - avoid_as # https://github.com/dart-lang/linter/issues/195 - avoid_init_to_null diff --git a/packages/flutter_tools/lib/flutter_tools.dart b/packages/flutter_tools/lib/flutter_tools.dart index 076b0f6258..653997b0e5 100644 --- a/packages/flutter_tools/lib/flutter_tools.dart +++ b/packages/flutter_tools/lib/flutter_tools.dart @@ -10,17 +10,17 @@ import 'src/flx.dart' as flx; /// Assembles a Flutter .flx file from a pre-existing manifest descriptor and a /// pre-compiled snapshot. Future assembleFlx({ - Map manifestDescriptor: const {}, + Map manifestDescriptor: const {}, File snapshotFile: null, String assetBasePath: flx.defaultAssetBasePath, String outputPath: flx.defaultFlxOutputPath, String privateKeyPath: flx.defaultPrivateKeyPath }) async { return flx.assemble( - manifestDescriptor: manifestDescriptor, - snapshotFile: snapshotFile, - assetBasePath: assetBasePath, - outputPath: outputPath, - privateKeyPath: privateKeyPath + manifestDescriptor: manifestDescriptor, + snapshotFile: snapshotFile, + assetBasePath: assetBasePath, + outputPath: outputPath, + privateKeyPath: privateKeyPath ); } diff --git a/packages/flutter_tools/lib/src/android/adb.dart b/packages/flutter_tools/lib/src/android/adb.dart index e8b648eb21..9d35daa23d 100644 --- a/packages/flutter_tools/lib/src/android/adb.dart +++ b/packages/flutter_tools/lib/src/android/adb.dart @@ -82,7 +82,7 @@ class Adb { Socket socket; bool isFirstNotification = true; - controller = new StreamController( + controller = new StreamController>( onListen: () async { socket = await Socket.connect(InternetAddress.LOOPBACK_IP_V4, adbServerPort); printTrace('--> host:track-devices'); @@ -121,7 +121,7 @@ class Adb { return controller.stream; } - Future _populateDeviceNames(List devices) async { + Future _populateDeviceNames(List devices) async { for (AdbDevice device in devices) { if (device.modelID == null) { // If we don't have a name of a device in our cache, call `device -l` to populate it. @@ -135,7 +135,7 @@ class Adb { } } - Future _populateDeviceCache() async { + Future _populateDeviceCache() async { List devices = await listDevices(); for (AdbDevice device in devices) _idToNameCache[device.id] = device.modelID; diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 4c63646db0..b1b1d50aef 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -180,7 +180,7 @@ class AndroidDevice extends Device { return true; } - Future _forwardObservatoryPort(int port) async { + Future _forwardObservatoryPort(int port) async { bool portWasZero = port == 0; try { @@ -485,8 +485,8 @@ class _AdbLogReader extends DeviceLogReader { new StreamController.broadcast(); Process _process; - StreamSubscription _stdoutSubscription; - StreamSubscription _stderrSubscription; + StreamSubscription _stdoutSubscription; + StreamSubscription _stderrSubscription; Stream get lines => _linesStreamController.stream; @@ -494,9 +494,9 @@ class _AdbLogReader extends DeviceLogReader { bool get isReading => _process != null; - Future get finished => _process != null ? _process.exitCode : new Future.value(0); + Future get finished => _process != null ? _process.exitCode : new Future.value(0); - Future start() async { + Future start() async { if (_process != null) throw new StateError('_AdbLogReader must be stopped before it can be started.'); @@ -516,7 +516,7 @@ class _AdbLogReader extends DeviceLogReader { _process.exitCode.then(_onExit); } - Future stop() async { + Future stop() async { if (_process == null) throw new StateError('_AdbLogReader must be started before it can be stopped.'); @@ -604,7 +604,7 @@ class _AndroidDevicePortForwarder extends DevicePortForwarder { return hostPort; } - Future unforward(ForwardedPort forwardedPort) async { + Future unforward(ForwardedPort forwardedPort) async { runCheckedSync(device.adbCommandForDevice( ['forward', '--remove', 'tcp:${forwardedPort.hostPort}'] )); diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart index b1bab87557..3b7dd1f04e 100644 --- a/packages/flutter_tools/lib/src/artifacts.dart +++ b/packages/flutter_tools/lib/src/artifacts.dart @@ -235,7 +235,7 @@ class ArtifactStore { /// Download a file from the given url and write it to the cache. /// If [unzip] is true, treat the url as a zip file, and unzip it to the /// directory given. - static Future _downloadFileToCache(Uri url, FileSystemEntity cachedFile, bool unzip) async { + static Future _downloadFileToCache(Uri url, FileSystemEntity cachedFile, bool unzip) async { if (!cachedFile.parent.existsSync()) cachedFile.parent.createSync(recursive: true); diff --git a/packages/flutter_tools/lib/src/base/file_system.dart b/packages/flutter_tools/lib/src/base/file_system.dart index f893eda48a..0ba8af0479 100644 --- a/packages/flutter_tools/lib/src/base/file_system.dart +++ b/packages/flutter_tools/lib/src/base/file_system.dart @@ -46,7 +46,7 @@ void restoreFileSystem() { } /// Uses in-memory replacments for `dart:io` functionality. Useful in tests. -void useInMemoryFileSystem({ cwd: '/', ExitFunction exitFunction }) { +void useInMemoryFileSystem({ String cwd: '/', ExitFunction exitFunction }) { MemoryFileSystem memFs = new MemoryFileSystem(); fs = memFs; syncFs = new SyncMemoryFileSystem(backedBy: memFs.storage); diff --git a/packages/flutter_tools/lib/src/base/logger.dart b/packages/flutter_tools/lib/src/base/logger.dart index 8d0b4f557c..46a3791044 100644 --- a/packages/flutter_tools/lib/src/base/logger.dart +++ b/packages/flutter_tools/lib/src/base/logger.dart @@ -4,7 +4,7 @@ import 'dart:io'; -final _terminal = new _AnsiTerminal(); +final _AnsiTerminal _terminal = new _AnsiTerminal(); abstract class Logger { bool get isVerbose => false; diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 46eff71bb9..db37581efc 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -57,9 +57,9 @@ Future runCommandAndStreamOutput(List cmd, { return await process.exitCode; } -Future runAndKill(List cmd, Duration timeout) { +Future runAndKill(List cmd, Duration timeout) { Future proc = runDetached(cmd); - return new Future.delayed(timeout, () async { + return new Future.delayed(timeout, () async { printTrace('Intentionally killing ${cmd[0]}'); Process.killPid((await proc).pid); }); diff --git a/packages/flutter_tools/lib/src/commands/analyze.dart b/packages/flutter_tools/lib/src/commands/analyze.dart index fb6e667b58..f1326c375e 100644 --- a/packages/flutter_tools/lib/src/commands/analyze.dart +++ b/packages/flutter_tools/lib/src/commands/analyze.dart @@ -223,7 +223,7 @@ class AnalyzeCommand extends FlutterCommand { // determine what all the various .packages files depend on PackageDependencyTracker dependencies = new PackageDependencyTracker(); - for (Directory directory in pubSpecDirectories.map((path) => new Directory(path))) { + for (Directory directory in pubSpecDirectories.map((String path) => new Directory(path))) { String pubSpecYamlPath = path.join(directory.path, 'pubspec.yaml'); File pubSpecYamlFile = new File(pubSpecYamlPath); if (pubSpecYamlFile.existsSync()) { @@ -242,8 +242,8 @@ class AnalyzeCommand extends FlutterCommand { dotPackages .readAsStringSync() .split('\n') - .where((line) => !line.startsWith(new RegExp(r'^ *#'))) - .forEach((line) { + .where((String line) => !line.startsWith(new RegExp(r'^ *#'))) + .forEach((String line) { int colon = line.indexOf(':'); if (colon > 0) dependencies.add(line.substring(0, colon), path.normalize(path.absolute(directory.path, path.fromUri(line.substring(colon+1)))), dotPackagesPath); @@ -634,7 +634,7 @@ class AnalysisServer { int _id = 0; - Future start() async { + Future start() async { String snapshot = path.join(sdk, 'bin/snapshots/analysis_server.dart.snapshot'); List args = [snapshot, '--sdk', sdk]; @@ -687,12 +687,12 @@ class AnalysisServer { dynamic response = JSON.decode(line); - if (response is Map) { + if (response is Map) { if (response['event'] != null) { String event = response['event']; dynamic params = response['params']; - if (params is Map) { + if (params is Map) { if (event == 'server.status') _handleStatus(response['params']); else if (event == 'analysis.errors') @@ -725,7 +725,7 @@ class AnalysisServer { _errorsController.add(new FileAnalysisErrors(file, errors)); } - Future dispose() async => _process?.kill(); + Future dispose() async => _process?.kill(); } class FileAnalysisErrors { diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 8e6fc399da..ec184752dd 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -135,7 +135,7 @@ All done! In order to run your application, type: printStatus('Creating project ${path.basename(projectName)}:'); - Map templateContext = { + Map templateContext = { 'projectName': projectName, 'androidIdentifier': _createAndroidIdentifier(projectName), 'iosIdentifier': _createUTIIdentifier(projectName), diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index ca63c15d4e..e2a477a33e 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -53,7 +53,7 @@ class DaemonCommand extends FlutterCommand { return JSON.decode(line); }); - Daemon daemon = new Daemon(commandStream, (Map command) { + Daemon daemon = new Daemon(commandStream, (Map command) { stdout.writeln('[${JSON.encode(command, toEncodable: _jsonEncodeObject)}]'); }, daemonCommand: this, notifyingLogger: notifyingLogger); @@ -73,7 +73,7 @@ typedef void DispatchComand(Map command); typedef Future CommandHandler(dynamic args); class Daemon { - Daemon(Stream commandStream, this.sendCommand, { + Daemon(Stream> commandStream, this.sendCommand, { this.daemonCommand, this.notifyingLogger }) { @@ -84,7 +84,7 @@ class Daemon { // Start listening. commandStream.listen( - (Map request) => _handleRequest(request), + (Map request) => _handleRequest(request), onDone: () => _onExitCompleter.complete(0) ); } @@ -106,7 +106,7 @@ class Daemon { Future get onExit => _onExitCompleter.future; - void _handleRequest(Map request) { + void _handleRequest(Map request) { // {id, method, params} // [id] is an opaque type to us. @@ -133,7 +133,7 @@ class Daemon { } } - void _send(Map map) => sendCommand(map); + void _send(Map map) => sendCommand(map); void shutdown() { _domainMap.values.forEach((Domain domain) => domain.dispose()); @@ -147,7 +147,7 @@ abstract class Domain { final Daemon daemon; final String name; - final Map _handlers = {}; + final Map _handlers = {}; void registerHandler(String name, CommandHandler handler) { _handlers[name] = handler; @@ -158,18 +158,18 @@ abstract class Domain { String toString() => name; void handleCommand(String command, dynamic id, dynamic args) { - new Future.sync(() { + new Future.sync(() { if (_handlers.containsKey(command)) return _handlers[command](args); throw 'command not understood: $name.$command'; - }).then((result) { + }).then((dynamic result) { if (result == null) { - _send({'id': id}); + _send({'id': id}); } else { - _send({'id': id, 'result': _toJsonable(result)}); + _send({'id': id, 'result': _toJsonable(result)}); } - }).catchError((error, trace) { - _send({'id': id, 'error': _toJsonable(error)}); + }).catchError((dynamic error, dynamic trace) { + _send({'id': id, 'error': _toJsonable(error)}); }); } @@ -180,7 +180,7 @@ abstract class Domain { _send(map); } - void _send(Map map) => daemon._send(map); + void _send(Map map) => daemon._send(map); void dispose() { } } @@ -212,12 +212,12 @@ class DaemonDomain extends Domain { StreamSubscription _subscription; Future version(dynamic args) { - return new Future.value(protocolVersion); + return new Future.value(protocolVersion); } - Future shutdown(dynamic args) { + Future shutdown(dynamic args) { Timer.run(() => daemon.shutdown()); - return new Future.value(); + return new Future.value(); } void dispose() { @@ -352,23 +352,23 @@ class DeviceDomain extends Domain { List devices = _discoverers.expand((PollingDeviceDiscovery discoverer) { return discoverer.devices; }).toList(); - return new Future.value(devices); + return new Future>.value(devices); } /// Enable device events. - Future enable(dynamic args) { + Future enable(dynamic args) { for (PollingDeviceDiscovery discoverer in _discoverers) { discoverer.startPolling(); } - return new Future.value(); + return new Future.value(); } /// Disable device events. - Future disable(dynamic args) { + Future disable(dynamic args) { for (PollingDeviceDiscovery discoverer in _discoverers) { discoverer.stopPolling(); } - return new Future.value(); + return new Future.value(); } void dispose() { @@ -398,7 +398,7 @@ String _enumToString(dynamic enumValue) { } dynamic _toJsonable(dynamic obj) { - if (obj is String || obj is int || obj is bool || obj is Map || obj is List || obj == null) + if (obj is String || obj is int || obj is bool || obj is Map || obj is List || obj == null) return obj; if (obj is Device) return obj; diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 5a1027c3a0..5cbbe6fdf5 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -106,7 +106,7 @@ class DriveCommand extends RunCommandBase { try { return await testRunner([testFile]) .then((_) => 0) - .catchError((error, stackTrace) { + .catchError((dynamic error, dynamic stackTrace) { printError('CAUGHT EXCEPTION: $error\n$stackTrace'); return 1; }); @@ -182,9 +182,9 @@ Future findTargetDevice() async { // we look for an Android device. If there's one, we use that. Otherwise, // we launch a new iOS Simulator. Device reusableDevice = devices.firstWhere( - (d) => d.isLocalEmulator, + (Device d) => d.isLocalEmulator, orElse: () { - return devices.firstWhere((d) => d is AndroidDevice, + return devices.firstWhere((Device d) => d is AndroidDevice, orElse: () => null); } ); @@ -210,7 +210,7 @@ Future findTargetDevice() async { return null; } else if (devices.length > 1) { printStatus('Found multiple connected devices:'); - printStatus(devices.map((d) => ' - ${d.name}\n').join('')); + printStatus(devices.map((Device d) => ' - ${d.name}\n').join('')); } printStatus('Using device ${devices.first.name}.'); return devices.first; diff --git a/packages/flutter_tools/lib/src/commands/logs.dart b/packages/flutter_tools/lib/src/commands/logs.dart index a5b9a01f94..9170c12ba3 100644 --- a/packages/flutter_tools/lib/src/commands/logs.dart +++ b/packages/flutter_tools/lib/src/commands/logs.dart @@ -38,7 +38,7 @@ class LogsCommand extends FlutterCommand { if (!logReader.isReading) await logReader.start(); - StreamSubscription subscription = logReader.lines.listen(printStatus); + StreamSubscription subscription = logReader.lines.listen(printStatus); // Wait for the log reader to be finished. int result = await logReader.finished; diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index 0826b3d0ed..26c7dfc171 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart @@ -185,7 +185,7 @@ Future startApp( } // Allow any stop commands from above to start work. - await new Future.delayed(Duration.ZERO); + await new Future.delayed(Duration.ZERO); if (install) { printTrace('Running install command.'); @@ -234,7 +234,7 @@ Future startApp( /// /// This does not fail if we're unable to connect, and times out after the given /// [timeout]. -Future delayUntilObservatoryAvailable(String host, int port, { +Future delayUntilObservatoryAvailable(String host, int port, { Duration timeout: const Duration(seconds: 10) }) async { Stopwatch stopwatch = new Stopwatch()..start(); @@ -246,10 +246,10 @@ Future delayUntilObservatoryAvailable(String host, int port, { try { WebSocket ws = await WebSocket.connect(url); printTrace('Connected to the observatory port.'); - ws.close().catchError((error) => null); + ws.close().catchError((dynamic error) => null); return; } catch (error) { - await new Future.delayed(new Duration(milliseconds: 250)); + await new Future.delayed(new Duration(milliseconds: 250)); } } diff --git a/packages/flutter_tools/lib/src/commands/run_mojo.dart b/packages/flutter_tools/lib/src/commands/run_mojo.dart index b3d759b9fb..3f9bde43c1 100644 --- a/packages/flutter_tools/lib/src/commands/run_mojo.dart +++ b/packages/flutter_tools/lib/src/commands/run_mojo.dart @@ -22,7 +22,7 @@ class RunMojoCommand extends FlutterCommand { final String description = 'Run a Flutter app in mojo (from github.com/domokit/mojo).'; final bool _hideCommand; - RunMojoCommand({ hideCommand: false }) : _hideCommand = hideCommand { + RunMojoCommand({ bool hideCommand: false }) : _hideCommand = hideCommand { argParser.addFlag('android', negatable: false, help: 'Run on an Android device'); argParser.addFlag('checked', negatable: false, help: 'Run Flutter in checked mode'); argParser.addFlag('mojo-debug', negatable: false, help: 'Use Debug build of mojo'); @@ -64,7 +64,7 @@ class RunMojoCommand extends FlutterCommand { } String _getMojoShellPath() { - final mojoBuildType = argResults['mojo-debug'] ? 'Debug' : 'Release'; + final String mojoBuildType = argResults['mojo-debug'] ? 'Debug' : 'Release'; return _makePathAbsolute(path.join(argResults['mojo-path'], 'out', mojoBuildType, 'mojo_shell')); } diff --git a/packages/flutter_tools/lib/src/commands/trace.dart b/packages/flutter_tools/lib/src/commands/trace.dart index 2f644c016a..4387a60269 100644 --- a/packages/flutter_tools/lib/src/commands/trace.dart +++ b/packages/flutter_tools/lib/src/commands/trace.dart @@ -41,7 +41,7 @@ class TraceCommand extends FlutterCommand { // Setting neither flags or both flags means do both commands and wait // duration seconds in between. device.startTracing(androidApp); - await new Future.delayed( + await new Future.delayed( new Duration(seconds: int.parse(argResults['duration'])), () => _stopTracing(device, androidApp) ); @@ -53,7 +53,7 @@ class TraceCommand extends FlutterCommand { return 0; } - Future _stopTracing(AndroidDevice android, AndroidApk androidApp) async { + Future _stopTracing(AndroidDevice android, AndroidApk androidApp) async { String tracePath = await android.stopTracing(androidApp, outPath: argResults['out']); if (tracePath == null) { printError('No trace file saved.'); diff --git a/packages/flutter_tools/lib/src/commands/update_packages.dart b/packages/flutter_tools/lib/src/commands/update_packages.dart index a17823d59b..e89c3dab28 100644 --- a/packages/flutter_tools/lib/src/commands/update_packages.dart +++ b/packages/flutter_tools/lib/src/commands/update_packages.dart @@ -24,7 +24,7 @@ Future _runPub(Directory directory, { bool upgrade: false }) async { } class UpdatePackagesCommand extends FlutterCommand { - UpdatePackagesCommand({ hideCommand: false }) : _hideCommand = hideCommand { + UpdatePackagesCommand({ bool hideCommand: false }) : _hideCommand = hideCommand { argParser.addFlag( 'upgrade', help: 'Run "pub upgrade" rather than "pub get".', diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 5b6406a89d..20f145b8f8 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -225,7 +225,7 @@ abstract class DevicePortForwarder { Future forward(int devicePort, {int hostPort: null}); /// Stops forwarding [forwardedPort]. - Future unforward(ForwardedPort forwardedPort); + Future unforward(ForwardedPort forwardedPort); } /// Read the log for a particular device. Subclasses must implement `hashCode` @@ -240,16 +240,16 @@ abstract class DeviceLogReader { Stream get lines; /// Start reading logs from the device. - Future start(); + Future start(); /// Actively reading lines from the log? bool get isReading; /// Actively stop reading logs from the device. - Future stop(); + Future stop(); /// Completes when the log is finished. - Future get finished; + Future get finished; int get hashCode; bool operator ==(dynamic other); diff --git a/packages/flutter_tools/lib/src/flx.dart b/packages/flutter_tools/lib/src/flx.dart index f2938a8497..79ca4d1a6e 100644 --- a/packages/flutter_tools/lib/src/flx.dart +++ b/packages/flutter_tools/lib/src/flx.dart @@ -38,7 +38,7 @@ class _Asset { const String _kMaterialIconsKey = 'fonts/MaterialIcons-Regular.ttf'; -List _getMaterialFonts() { +List> _getMaterialFonts() { return [{ 'family': 'MaterialIcons', 'fonts': [{ @@ -57,7 +57,7 @@ List<_Asset> _getMaterialAssets() { ]; } -Map<_Asset, List<_Asset>> _parseAssets(Map manifestDescriptor, String assetBase) { +Map<_Asset, List<_Asset>> _parseAssets(Map manifestDescriptor, String assetBase) { Map<_Asset, List<_Asset>> result = <_Asset, List<_Asset>>{}; if (manifestDescriptor == null) return result; @@ -112,8 +112,8 @@ ZipEntry _createAssetManifest(Map<_Asset, List<_Asset>> assets) { return new ZipEntry.fromString('AssetManifest.json', JSON.encode(json)); } -ZipEntry _createFontManifest(Map manifestDescriptor, List additionalFonts) { - List fonts = []; +ZipEntry _createFontManifest(Map manifestDescriptor, List> additionalFonts) { + List> fonts = >[]; if (additionalFonts != null) fonts.addAll(additionalFonts); if (manifestDescriptor != null && manifestDescriptor.containsKey('fonts')) @@ -167,7 +167,7 @@ Future build( String workingDirPath: defaultWorkingDirPath, bool precompiledSnapshot: false }) async { - Map manifestDescriptor = _loadManifest(manifestPath); + Map manifestDescriptor = _loadManifest(manifestPath); String assetBasePath = path.dirname(path.absolute(manifestPath)); File snapshotFile; @@ -197,7 +197,7 @@ Future build( } Future assemble({ - Map manifestDescriptor: const {}, + Map manifestDescriptor: const {}, File snapshotFile, String assetBasePath: defaultAssetBasePath, String outputPath: defaultFlxOutputPath, @@ -244,7 +244,7 @@ Future assemble({ if (fontManifest != null) zipBuilder.addEntry(fontManifest); - AsymmetricKeyPair keyPair = keyPairFromPrivateKeyFileSync(privateKeyPath); + AsymmetricKeyPair keyPair = keyPairFromPrivateKeyFileSync(privateKeyPath); printTrace('KeyPair from $privateKeyPath: $keyPair.'); if (keyPair != null) { diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index 2408073318..6f9157567c 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -253,8 +253,8 @@ class _IOSDeviceLogReader extends DeviceLogReader { new StreamController.broadcast(); Process _process; - StreamSubscription _stdoutSubscription; - StreamSubscription _stderrSubscription; + StreamSubscription _stdoutSubscription; + StreamSubscription _stderrSubscription; Stream get lines => _linesStreamController.stream; @@ -262,13 +262,15 @@ class _IOSDeviceLogReader extends DeviceLogReader { bool get isReading => _process != null; - Future get finished => - _process != null ? _process.exitCode : new Future.value(0); + Future get finished { + return _process != null ? _process.exitCode : new Future.value(0); + } - Future start() async { + Future start() async { if (_process != null) { throw new StateError( - '_IOSDeviceLogReader must be stopped before it can be started.'); + '_IOSDeviceLogReader must be stopped before it can be started.' + ); } _process = await runCommand([device.loggerPath]); _stdoutSubscription = @@ -280,10 +282,11 @@ class _IOSDeviceLogReader extends DeviceLogReader { _process.exitCode.then(_onExit); } - Future stop() async { + Future stop() async { if (_process == null) { throw new StateError( - '_IOSDeviceLogReader must be started before it can be stopped.'); + '_IOSDeviceLogReader must be started before it can be stopped.' + ); } _stdoutSubscription?.cancel(); _stdoutSubscription = null; @@ -341,7 +344,7 @@ class _IOSDevicePortForwarder extends DevicePortForwarder { return hostPort; } - Future unforward(ForwardedPort forwardedPort) async { + Future unforward(ForwardedPort forwardedPort) async { // TODO(chinmaygarde): Implement. } } diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 0b836577d8..cd7215590a 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -181,7 +181,7 @@ String _getIOSEngineRevision(ApplicationPackage app) { } } -Future _addServicesToBundle(Directory bundle) async { +Future _addServicesToBundle(Directory bundle) async { List> services = []; printTrace("Trying to resolve native pub services."); @@ -200,7 +200,7 @@ Future _addServicesToBundle(Directory bundle) async { _copyServiceDefinitionsManifest(services, manifestFile); } -Future _copyServiceFrameworks(List> services, Directory frameworksDirectory) async { +Future _copyServiceFrameworks(List> services, Directory frameworksDirectory) async { printTrace("Copying service frameworks to '${path.absolute(frameworksDirectory.path)}'."); frameworksDirectory.createSync(recursive: true); for (Map service in services) { diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index da2c88e1c1..7cf761d615 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -79,7 +79,7 @@ class SimControl { connected = await _isAnyConnected(); if (!connected) { printStatus('Still waiting for iOS Simulator to boot...'); - await new Future.delayed(new Duration(seconds: 1)); + await new Future.delayed(new Duration(seconds: 1)); } attempted++; } @@ -106,7 +106,7 @@ class SimControl { // Delete any old test devices getDevices() - .where((d) => d.name == _kFlutterTestDevice) + .where((SimDevice d) => d.name == _kFlutterTestDevice) .forEach(_deleteDevice); // Create new device @@ -114,15 +114,15 @@ class SimControl { printTrace(args.join(' ')); runCheckedSync(args); - return getDevices().firstWhere((d) => d.name == _kFlutterTestDevice); + return getDevices().firstWhere((SimDevice d) => d.name == _kFlutterTestDevice); } String _findSuitableDeviceType() { List> allTypes = _list(SimControlListSection.devicetypes); List> usableTypes = allTypes - .where((info) => info['name'].startsWith('iPhone')) + .where((Map info) => info['name'].startsWith('iPhone')) .toList() - ..sort((r1, r2) => -compareIphoneVersions(r1['identifier'], r2['identifier'])); + ..sort((Map r1, Map r2) => -compareIphoneVersions(r1['identifier'], r2['identifier'])); if (usableTypes.isEmpty) { printError( @@ -139,9 +139,9 @@ class SimControl { String _findSuitableRuntime() { List> allRuntimes = _list(SimControlListSection.runtimes); List> usableRuntimes = allRuntimes - .where((info) => info['name'].startsWith('iOS')) + .where((Map info) => info['name'].startsWith('iOS')) .toList() - ..sort((r1, r2) => -compareIosVersions(r1['version'], r2['version'])); + ..sort((Map r1, Map r2) => -compareIosVersions(r1['version'], r2['version'])); if (usableRuntimes.isEmpty) { printError( @@ -206,7 +206,7 @@ class SimControl { Map devicesSection = _list(SimControlListSection.devices); for (String deviceCategory in devicesSection.keys) { - List devicesData = devicesSection[deviceCategory]; + List> devicesData = devicesSection[deviceCategory]; for (Map data in devicesData) { devices.add(new SimDevice(deviceCategory, data)); @@ -232,15 +232,12 @@ class SimControl { if (_trackDevicesControler == null) { Timer timer; Set deviceIds = new Set(); - - _trackDevicesControler = new StreamController.broadcast( + _trackDevicesControler = new StreamController>.broadcast( onListen: () { timer = new Timer.periodic(new Duration(seconds: 4), (Timer timer) { List devices = getConnectedDevices(); - - if (_updateDeviceIds(devices, deviceIds)) { + if (_updateDeviceIds(devices, deviceIds)) _trackDevicesControler.add(devices); - } }); }, onCancel: () { timer?.cancel(); @@ -290,13 +287,14 @@ class SimControl { /// Enumerates all data sections of `xcrun simctl list --json` command. class SimControlListSection { - static const devices = const SimControlListSection._('devices'); - static const devicetypes = const SimControlListSection._('devicetypes'); - static const runtimes = const SimControlListSection._('runtimes'); - static const pairs = const SimControlListSection._('pairs'); + const SimControlListSection._(this.name); final String name; - const SimControlListSection._(this.name); + + static const SimControlListSection devices = const SimControlListSection._('devices'); + static const SimControlListSection devicetypes = const SimControlListSection._('devicetypes'); + static const SimControlListSection runtimes = const SimControlListSection._('runtimes'); + static const SimControlListSection pairs = const SimControlListSection._('pairs'); } class SimDevice { @@ -580,12 +578,12 @@ class _IOSSimulatorLogReader extends DeviceLogReader { // We log from two logs: the device and the system log. Process _deviceProcess; - StreamSubscription _deviceStdoutSubscription; - StreamSubscription _deviceStderrSubscription; + StreamSubscription _deviceStdoutSubscription; + StreamSubscription _deviceStderrSubscription; Process _systemProcess; - StreamSubscription _systemStdoutSubscription; - StreamSubscription _systemStderrSubscription; + StreamSubscription _systemStdoutSubscription; + StreamSubscription _systemStderrSubscription; Stream get lines => _linesStreamController.stream; @@ -593,13 +591,15 @@ class _IOSSimulatorLogReader extends DeviceLogReader { bool get isReading => (_deviceProcess != null) && (_systemProcess != null); - Future get finished => - (_deviceProcess != null) ? _deviceProcess.exitCode : new Future.value(0); + Future get finished { + return (_deviceProcess != null) ? _deviceProcess.exitCode : new Future.value(0); + } - Future start() async { + Future start() async { if (isReading) { throw new StateError( - '_IOSSimulatorLogReader must be stopped before it can be started.'); + '_IOSSimulatorLogReader must be stopped before it can be started.' + ); } // TODO(johnmccutchan): Add a ProcessSet abstraction that handles running @@ -630,10 +630,11 @@ class _IOSSimulatorLogReader extends DeviceLogReader { _systemProcess.exitCode.then(_onSystemExit); } - Future stop() async { + Future stop() async { if (!isReading) { throw new StateError( - '_IOSSimulatorLogReader must be started before it can be stopped.'); + '_IOSSimulatorLogReader must be started before it can be stopped.' + ); } if (_deviceProcess != null) { await _deviceProcess.kill(); @@ -774,7 +775,7 @@ int compareIphoneVersions(String id1, String id2) { return v1.compareTo(v2); // Sorted in the least preferred first order. - const qualifiers = const ['-Plus', '', 's-Plus', 's']; + const List qualifiers = const ['-Plus', '', 's-Plus', 's']; int q1 = qualifiers.indexOf(m1[2]); int q2 = qualifiers.indexOf(m2[2]); @@ -801,7 +802,7 @@ class _IOSSimulatorDevicePortForwarder extends DevicePortForwarder { return hostPort; } - Future unforward(ForwardedPort forwardedPort) async { + Future unforward(ForwardedPort forwardedPort) async { _ports.remove(forwardedPort); } } diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index 5351d1c7ed..39eb6b3ef8 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -35,11 +35,11 @@ abstract class FlutterCommand extends Command { List get buildConfigurations => runner.buildConfigurations; - Future downloadToolchain() async { + Future downloadToolchain() async { toolchain ??= await Toolchain.forConfigs(buildConfigurations); } - Future downloadApplicationPackages() async { + Future downloadApplicationPackages() async { applicationPackages ??= await ApplicationPackageStore.forConfigs(buildConfigurations); } @@ -127,7 +127,7 @@ abstract class FlutterCommand extends Command { void addTargetOption() { argParser.addOption('target', abbr: 't', - callback: (val) => _targetSpecified = true, + callback: (dynamic val) => _targetSpecified = true, defaultsTo: flx.defaultMainPath, help: 'Target app path / main entry-point file.'); _targetOptionSpecified = true; diff --git a/packages/flutter_tools/lib/src/service_protocol.dart b/packages/flutter_tools/lib/src/service_protocol.dart index ffbbdfa144..db3bbbed20 100644 --- a/packages/flutter_tools/lib/src/service_protocol.dart +++ b/packages/flutter_tools/lib/src/service_protocol.dart @@ -19,7 +19,7 @@ class ServiceProtocolDiscovery { } final DeviceLogReader _logReader; - Completer _completer = new Completer(); + Completer _completer = new Completer(); /// The [Future] returned by this function will complete when the next /// service protocol port is found. @@ -32,21 +32,20 @@ class ServiceProtocolDiscovery { if (line.startsWith('Observatory listening on http://')) { try { RegExp portExp = new RegExp(r"\d+.\d+.\d+.\d+:(\d+)"); - var port = portExp.firstMatch(line).group(1); + String port = portExp.firstMatch(line).group(1); portNumber = int.parse(port); } catch (_) { // Ignore errors. } } - if (portNumber != 0) { + if (portNumber != 0) _located(portNumber); - } } void _located(int port) { assert(_completer != null); assert(!_completer.isCompleted); _completer.complete(port); - _completer = new Completer(); + _completer = new Completer(); } } diff --git a/packages/flutter_tools/lib/src/services.dart b/packages/flutter_tools/lib/src/services.dart index ce08d094b1..552acef5ac 100644 --- a/packages/flutter_tools/lib/src/services.dart +++ b/packages/flutter_tools/lib/src/services.dart @@ -25,7 +25,7 @@ dynamic _loadYamlFile(String path) { /// Loads all services specified in `flutter.yaml`. Parses each service config file, /// storing metadata in [services] and the list of jar files in [jars]. -Future parseServiceConfigs( +Future parseServiceConfigs( List> services, { List jars } ) async { if (!ArtifactStore.isPackageRootValid) { diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index 81d0c4b945..61cbba08d5 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -55,11 +55,11 @@ Future _startProcess(String mainPath, { String packageRoot }) { } class FlutterPlatform extends PlatformPlugin { - StreamChannel loadChannel(String mainPath, TestPlatform platform) { + StreamChannel loadChannel(String mainPath, TestPlatform platform) { return StreamChannelCompleter.fromFuture(_startTest(mainPath)); } - Future _startTest(String mainPath) async { + Future> _startTest(String mainPath) async { _ServerInfo info = await _startServer(); Directory tempDir = Directory.systemTemp.createTempSync( 'dart_test_listener'); @@ -108,19 +108,19 @@ void main() { try { WebSocket socket = await info.socket; - StreamChannel channel = new StreamChannel(socket.map(JSON.decode), socket); + StreamChannel channel = new StreamChannel(socket.map(JSON.decode), socket); return channel.transformStream( - new StreamTransformer.fromHandlers( - handleDone: (sink) { + new StreamTransformer.fromHandlers( + handleDone: (EventSink sink) { finalize(); sink.close(); } ) - ).transformSink(new StreamSinkTransformer.fromHandlers( - handleData: (data, StreamSink sink) { + ).transformSink(new StreamSinkTransformer.fromHandlers( + handleData: (String data, StreamSink sink) { sink.add(JSON.encode(data)); }, - handleDone: (sink) { + handleDone: (EventSink sink) { finalize(); sink.close(); } diff --git a/packages/flutter_tools/test/analyze_test.dart b/packages/flutter_tools/test/analyze_test.dart index bddf95fcaf..2074cb15f5 100644 --- a/packages/flutter_tools/test/analyze_test.dart +++ b/packages/flutter_tools/test/analyze_test.dart @@ -36,7 +36,7 @@ void main() { server = new AnalysisServer(dartSdkPath, [tempDir.path]); int errorCount = 0; - Future onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first; + Future onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first; server.onErrors.listen((FileAnalysisErrors errors) => errorCount += errors.errors.length); await server.start(); @@ -55,7 +55,7 @@ void main() { server = new AnalysisServer(dartSdkPath, [tempDir.path]); int errorCount = 0; - Future onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first; + Future onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first; server.onErrors.listen((FileAnalysisErrors errors) => errorCount += errors.errors.length); await server.start(); diff --git a/packages/flutter_tools/test/daemon_test.dart b/packages/flutter_tools/test/daemon_test.dart index fa345315b6..793f0b9728 100644 --- a/packages/flutter_tools/test/daemon_test.dart +++ b/packages/flutter_tools/test/daemon_test.dart @@ -45,15 +45,15 @@ void main() { }); _testUsingContext('daemon.version', () async { - StreamController> commands = new StreamController(); - StreamController> responses = new StreamController(); + StreamController> commands = new StreamController>(); + StreamController> responses = new StreamController>(); daemon = new Daemon( commands.stream, (Map result) => responses.add(result), notifyingLogger: notifyingLogger ); - commands.add({'id': 0, 'method': 'daemon.version'}); - Map response = await responses.stream.where(_notEvent).first; + commands.add({'id': 0, 'method': 'daemon.version'}); + Map response = await responses.stream.where(_notEvent).first; expect(response['id'], 0); expect(response['result'], isNotEmpty); expect(response['result'] is String, true); @@ -61,8 +61,8 @@ void main() { _testUsingContext('daemon.logMessage', () { return appContext.runInZone(() async { - StreamController> commands = new StreamController(); - StreamController> responses = new StreamController(); + StreamController> commands = new StreamController>(); + StreamController> responses = new StreamController>(); daemon = new Daemon( commands.stream, (Map result) => responses.add(result), @@ -81,8 +81,8 @@ void main() { }); _testUsingContext('daemon.shutdown', () async { - StreamController> commands = new StreamController(); - StreamController> responses = new StreamController(); + StreamController> commands = new StreamController>(); + StreamController> responses = new StreamController>(); daemon = new Daemon( commands.stream, (Map result) => responses.add(result), @@ -98,8 +98,8 @@ void main() { DaemonCommand command = new DaemonCommand(); applyMocksToCommand(command); - StreamController> commands = new StreamController(); - StreamController> responses = new StreamController(); + StreamController> commands = new StreamController>(); + StreamController> responses = new StreamController>(); daemon = new Daemon( commands.stream, (Map result) => responses.add(result), @@ -108,21 +108,21 @@ void main() { ); commands.add({ 'id': 0, 'method': 'app.stop' }); - Map response = await responses.stream.where(_notEvent).first; + Map response = await responses.stream.where(_notEvent).first; expect(response['id'], 0); expect(response['error'], contains('deviceId is required')); }); _testUsingContext('device.getDevices', () async { - StreamController> commands = new StreamController(); - StreamController> responses = new StreamController(); + StreamController> commands = new StreamController>(); + StreamController> responses = new StreamController>(); daemon = new Daemon( commands.stream, (Map result) => responses.add(result), notifyingLogger: notifyingLogger ); commands.add({'id': 0, 'method': 'device.getDevices'}); - Map response = await responses.stream.where(_notEvent).first; + Map response = await responses.stream.where(_notEvent).first; expect(response['id'], 0); expect(response['result'], isList); }); diff --git a/packages/flutter_tools/test/service_protocol_test.dart b/packages/flutter_tools/test/service_protocol_test.dart index 3498b5c2f6..5f5d5c6bdf 100644 --- a/packages/flutter_tools/test/service_protocol_test.dart +++ b/packages/flutter_tools/test/service_protocol_test.dart @@ -16,7 +16,7 @@ void main() { ServiceProtocolDiscovery discoverer = new ServiceProtocolDiscovery(logReader); // Get next port future. - Future nextPort = discoverer.nextPort(); + Future nextPort = discoverer.nextPort(); expect(nextPort, isNotNull); // Inject some lines. logReader.addLine('HELLO WORLD'); diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index 3ede26c92a..db5283c39a 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -72,11 +72,11 @@ class MockDeviceManager implements DeviceManager { String specifiedDeviceId; bool get hasSpecifiedDeviceId => specifiedDeviceId != null; - Future> getAllConnectedDevices() => new Future.value(devices); + Future> getAllConnectedDevices() => new Future>.value(devices); Future getDeviceById(String deviceId) { Device device = devices.firstWhere((Device device) => device.id == deviceId, orElse: () => null); - return new Future.value(device); + return new Future.value(device); } Future> getDevices() async { diff --git a/packages/flutter_tools/test/src/mocks.dart b/packages/flutter_tools/test/src/mocks.dart index bbb09dd164..62d6c369eb 100644 --- a/packages/flutter_tools/test/src/mocks.dart +++ b/packages/flutter_tools/test/src/mocks.dart @@ -52,7 +52,7 @@ class MockDeviceLogReader extends DeviceLogReader { final StreamController _linesStreamController = new StreamController.broadcast(); - final Completer _finishedCompleter = new Completer(); + final Completer _finishedCompleter = new Completer(); Stream get lines => _linesStreamController.stream; @@ -62,21 +62,20 @@ class MockDeviceLogReader extends DeviceLogReader { bool _started = false; - Future start() { + Future start() async { assert(!_started); _started = true; - return new Future.value(this); } bool get isReading => _started; - Future stop() { + Future stop() { assert(_started); _started = false; - return new Future.value(this); + return new Future.value(); } - Future get finished => _finishedCompleter.future; + Future get finished => _finishedCompleter.future; } void applyMocksToCommand(FlutterCommand command) { diff --git a/packages/flutter_tools/test/stop_test.dart b/packages/flutter_tools/test/stop_test.dart index d3c5f31c00..0e3fc235a8 100644 --- a/packages/flutter_tools/test/stop_test.dart +++ b/packages/flutter_tools/test/stop_test.dart @@ -18,7 +18,7 @@ void main() { StopCommand command = new StopCommand(); applyMocksToCommand(command); MockAndroidDevice device = new MockAndroidDevice(); - when(device.stopApp(any)).thenReturn(new Future.value(true)); + when(device.stopApp(any)).thenReturn(new Future.value(true)); testDeviceManager.addDevice(device); return createTestCommandRunner(command).run(['stop']).then((int code) { expect(code, equals(0)); @@ -29,7 +29,7 @@ void main() { StopCommand command = new StopCommand(); applyMocksToCommand(command); MockIOSDevice device = new MockIOSDevice(); - when(device.stopApp(any)).thenReturn(new Future.value(true)); + when(device.stopApp(any)).thenReturn(new Future.value(true)); testDeviceManager.addDevice(device); return createTestCommandRunner(command).run(['stop']).then((int code) { diff --git a/packages/flx/lib/bundle.dart b/packages/flx/lib/bundle.dart index 613cf21e68..cfd6080ecf 100644 --- a/packages/flx/lib/bundle.dart +++ b/packages/flx/lib/bundle.dart @@ -72,14 +72,14 @@ class Bundle { this.path, this.manifest, List contentBytes, - AsymmetricKeyPair keyPair + AsymmetricKeyPair keyPair }) : _contentBytes = contentBytes { assert(path != null); assert(manifest != null); assert(_contentBytes != null); manifestBytes = serializeManifest(manifest, keyPair?.publicKey, _contentBytes); signatureBytes = signManifest(manifestBytes, keyPair?.privateKey); - _openContentStream = () => new Stream.fromIterable(>[_contentBytes]); + _openContentStream = () => new Stream>.fromIterable(>[_contentBytes]); } final String path; diff --git a/packages/flx/lib/signing.dart b/packages/flx/lib/signing.dart index 6c2f2aec11..802aecfd1a 100644 --- a/packages/flx/lib/signing.dart +++ b/packages/flx/lib/signing.dart @@ -12,7 +12,7 @@ import 'package:bignum/bignum.dart'; import 'package:crypto/crypto.dart'; import 'package:pointycastle/pointycastle.dart'; -export 'package:pointycastle/pointycastle.dart' show AsymmetricKeyPair; +export 'package:pointycastle/pointycastle.dart' show AsymmetricKeyPair, PublicKey, PrivateKey; // The ECDSA algorithm parameters we're using. These match the parameters used // by the Flutter updater package. @@ -50,7 +50,7 @@ class CipherParameters { SecureRandom _random; void _initRandom(Uint8List key, Uint8List iv) { KeyParameter keyParam = new KeyParameter(key); - ParametersWithIV params = new ParametersWithIV(keyParam, iv); + ParametersWithIV params = new ParametersWithIV(keyParam, iv); _random = new SecureRandom('AES/CTR/AUTO-SEED-PRNG') ..seed(params); } @@ -65,7 +65,7 @@ final CipherParameters _params = CipherParameters._init(); // Returns a serialized manifest, with the public key and hash of the content // included. -Uint8List serializeManifest(Map manifestDescriptor, ECPublicKey publicKey, Uint8List zipBytes) { +Uint8List serializeManifest(Map manifestDescriptor, ECPublicKey publicKey, Uint8List zipBytes) { if (manifestDescriptor == null) return null; final List kSavedKeys = [ @@ -73,8 +73,8 @@ Uint8List serializeManifest(Map manifestDescriptor, ECPublicKey publicKey, Uint8 'version', 'update-url' ]; - Map outputManifest = new Map(); - manifestDescriptor.forEach((key, value) { + Map outputManifest = new Map(); + manifestDescriptor.forEach((String key, dynamic value) { if (kSavedKeys.contains(key)) outputManifest[key] = value; }); @@ -97,8 +97,8 @@ Uint8List signManifest(Uint8List manifestBytes, ECPrivateKey privateKey) { if (manifestBytes == null || privateKey == null) return new Uint8List(0); Signer signer = new Signer(_params.signerAlgorithm); - PrivateKeyParameter params = new PrivateKeyParameter(privateKey); - signer.init(true, new ParametersWithRandom(params, _params.random)); + PrivateKeyParameter params = new PrivateKeyParameter(privateKey); + signer.init(true, new ParametersWithRandom>(params, _params.random)); ECSignature signature = signer.generateSignature(manifestBytes); ASN1Sequence asn1 = new ASN1Sequence() ..add(new ASN1Integer(signature.r)) @@ -115,10 +115,10 @@ bool verifyManifestSignature(Map manifest, List keyBytes = BASE64.decode(manifest['key']); ECPoint q = _params.domain.curve.decodePoint(keyBytes); - ECPublicKey publicKey = new ECPublicKey(q, _params.domain); + PublicKey publicKey = new ECPublicKey(q, _params.domain); Signer signer = new Signer(_params.signerAlgorithm); - signer.init(false, new PublicKeyParameter(publicKey)); + signer.init(false, new PublicKeyParameter(publicKey)); return signer.verifySignature(manifestBytes, signature); } @@ -166,24 +166,24 @@ ECSignature _asn1ParseSignature(Uint8List signature) { } } -ECPublicKey _publicKeyFromPrivateKey(ECPrivateKey privateKey) { +PublicKey _publicKeyFromPrivateKey(ECPrivateKey privateKey) { ECPoint Q = privateKey.parameters.G * privateKey.d; return new ECPublicKey(Q, privateKey.parameters); } -AsymmetricKeyPair keyPairFromPrivateKeyFileSync(String privateKeyPath) { +AsymmetricKeyPair keyPairFromPrivateKeyFileSync(String privateKeyPath) { File file = new File(privateKeyPath); if (!file.existsSync()) return null; return keyPairFromPrivateKeyBytes(file.readAsBytesSync()); } -AsymmetricKeyPair keyPairFromPrivateKeyBytes(List privateKeyBytes) { +AsymmetricKeyPair keyPairFromPrivateKeyBytes(List privateKeyBytes) { ECPrivateKey privateKey = _asn1ParsePrivateKey( _params.domain, new Uint8List.fromList(privateKeyBytes)); if (privateKey == null) return null; - ECPublicKey publicKey = _publicKeyFromPrivateKey(privateKey); - return new AsymmetricKeyPair(publicKey, privateKey); + PublicKey publicKey = _publicKeyFromPrivateKey(privateKey); + return new AsymmetricKeyPair(publicKey, privateKey); } diff --git a/packages/flx/test/bundle_test.dart b/packages/flx/test/bundle_test.dart index 521502aea4..89d7d856ec 100644 --- a/packages/flx/test/bundle_test.dart +++ b/packages/flx/test/bundle_test.dart @@ -8,7 +8,7 @@ import 'package:flx/bundle.dart'; import 'package:flx/signing.dart'; import 'package:test/test.dart'; -Future main() async { +Future main() async { // The following constant was generated via the openssl shell commands: // openssl ecparam -genkey -name prime256v1 -out privatekey.pem // openssl ec -in privatekey.pem -outform DER | base64 @@ -28,9 +28,10 @@ Future main() async { Directory tempDir = await Directory.systemTemp.createTempSync('bundle_test'); String bundlePath = tempDir.path + '/bundle.flx'; - AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); + AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); Map manifest = JSON.decode(UTF8.decode( - serializeManifest(kManifest, keyPair.publicKey, kTestBytes))); + serializeManifest(kManifest, keyPair.publicKey, kTestBytes) + )); test('verifyContent works', () async { Bundle bundle = new Bundle.fromContent( diff --git a/packages/flx/test/signing_test.dart b/packages/flx/test/signing_test.dart index 585ca797c4..e1c8f7cee9 100644 --- a/packages/flx/test/signing_test.dart +++ b/packages/flx/test/signing_test.dart @@ -8,7 +8,7 @@ import 'package:crypto/crypto.dart'; import 'package:flx/signing.dart'; import 'package:test/test.dart'; -Future main() async { +Future main() async { // The following constant was generated via the openssl shell commands: // openssl ecparam -genkey -name prime256v1 -out privatekey.pem // openssl ec -in privatekey.pem -outform DER | base64 @@ -42,18 +42,21 @@ Future main() async { keyGenerator.init(keyGeneratorParams); test('can read openssl key pair', () { - AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); + AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); expect(keyPair != null, equals(true)); - expect(keyPair.privateKey.d.intValue(), equals(kPrivateKeyD)); - expect(keyPair.publicKey.Q.x.toBigInteger().intValue(), equals(kPublicKeyQx)); - expect(keyPair.publicKey.Q.y.toBigInteger().intValue(), equals(kPublicKeyQy)); + ECPrivateKey keyPairPrivateKey = keyPair.privateKey; + ECPublicKey keyPairPublicKey = keyPair.publicKey; + expect(keyPairPrivateKey.d.intValue(), equals(kPrivateKeyD)); + expect(keyPairPublicKey.Q.x.toBigInteger().intValue(), equals(kPublicKeyQx)); + expect(keyPairPublicKey.Q.y.toBigInteger().intValue(), equals(kPublicKeyQy)); }); test('serializeManifest adds key and content-hash', () { - AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); - Uint8List manifestBytes = serializeManifest(kManifest, keyPair.publicKey, kTestBytes); + AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); + ECPublicKey keyPairPublicKey = keyPair.publicKey; + Uint8List manifestBytes = serializeManifest(kManifest, keyPairPublicKey, kTestBytes); Map decodedManifest = JSON.decode(UTF8.decode(manifestBytes)); - String expectedKey = BASE64.encode(keyPair.publicKey.Q.getEncoded()); + String expectedKey = BASE64.encode(keyPairPublicKey.Q.getEncoded()); expect(decodedManifest != null, equals(true)); expect(decodedManifest['name'], equals(kManifest['name'])); expect(decodedManifest['version'], equals(kManifest['version'])); @@ -62,10 +65,13 @@ Future main() async { }); test('signManifest and verifyManifestSignature work', () { - AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); + AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); + ECPrivateKey keyPairPrivateKey = keyPair.privateKey; + ECPublicKey keyPairPublicKey = keyPair.publicKey; Map manifest = JSON.decode(UTF8.decode( - serializeManifest(kManifest, keyPair.publicKey, kTestBytes))); - Uint8List signatureBytes = signManifest(kTestBytes, keyPair.privateKey); + serializeManifest(kManifest, keyPairPublicKey, kTestBytes)) + ); + Uint8List signatureBytes = signManifest(kTestBytes, keyPairPrivateKey); bool verifies = verifyManifestSignature(manifest, kTestBytes, signatureBytes); expect(verifies, equals(true)); @@ -79,11 +85,14 @@ Future main() async { }); test('signing works with arbitrary key', () { - AsymmetricKeyPair keyPair = keyGenerator.generateKeyPair(); - String failReason = 'offending private key: ${keyPair.privateKey.d}'; + AsymmetricKeyPair keyPair = keyGenerator.generateKeyPair(); + ECPrivateKey keyPairPrivateKey = keyPair.privateKey; + ECPublicKey keyPairPublicKey = keyPair.publicKey; + String failReason = 'offending private key: ${keyPairPrivateKey.d}'; Map manifest = JSON.decode(UTF8.decode( - serializeManifest(kManifest, keyPair.publicKey, kTestBytes))); - Uint8List signatureBytes = signManifest(kTestBytes, keyPair.privateKey); + serializeManifest(kManifest, keyPairPublicKey, kTestBytes)) + ); + Uint8List signatureBytes = signManifest(kTestBytes, keyPairPrivateKey); bool verifies = verifyManifestSignature(manifest, kTestBytes, signatureBytes); expect(verifies, equals(true), reason: failReason); @@ -97,17 +106,18 @@ Future main() async { }); test('verifyContentHash works', () async { - Stream contentStream = new Stream.fromIterable(kTestBytesList); + Stream contentStream = new Stream.fromIterable(kTestBytesList); bool verifies = await verifyContentHash(new BigInteger(kTestHash), contentStream); expect(verifies, equals(true)); // Ensure it fails with invalid hash or content. - contentStream = new Stream.fromIterable(kTestBytesList); + contentStream = new Stream.fromIterable(kTestBytesList); verifies = await verifyContentHash(new BigInteger(0xdeadbeef), contentStream); expect(verifies, equals(false)); - Stream badContentStream = - new Stream.fromIterable([new Uint8List.fromList([42])]); + Stream badContentStream = new Stream.fromIterable( + [new Uint8List.fromList([42])] + ); verifies = await verifyContentHash(new BigInteger(kTestHash), badContentStream); expect(verifies, equals(false)); });