diff --git a/packages/flutter_driver/analysis_options.yaml b/packages/flutter_driver/analysis_options.yaml new file mode 100644 index 0000000000..a08bda2904 --- /dev/null +++ b/packages/flutter_driver/analysis_options.yaml @@ -0,0 +1,8 @@ +# Override the parent analysis_options until all the repo has implicit-casts: false + +include: ../analysis_options.yaml + +analyzer: + strong-mode: + implicit-casts: false + implicit-dynamic: false diff --git a/packages/flutter_driver/lib/src/common/diagnostics_tree.dart b/packages/flutter_driver/lib/src/common/diagnostics_tree.dart index 7c4bb7f097..595cb8cee0 100644 --- a/packages/flutter_driver/lib/src/common/diagnostics_tree.dart +++ b/packages/flutter_driver/lib/src/common/diagnostics_tree.dart @@ -33,7 +33,7 @@ class GetDiagnosticsTree extends CommandWithTarget { super(finder, timeout: timeout); /// Deserializes this command from the value generated by [serialize]. - GetDiagnosticsTree.deserialize(Map json) + GetDiagnosticsTree.deserialize(Map json) : subtreeDepth = int.parse(json['subtreeDepth']), includeProperties = json['includeProperties'] == 'true', diagnosticsType = _diagnosticsTypeIndex.lookupBySimpleName(json['diagnosticsType']), diff --git a/packages/flutter_driver/lib/src/common/find.dart b/packages/flutter_driver/lib/src/common/find.dart index f920a407c6..1e1ba2b2b1 100644 --- a/packages/flutter_driver/lib/src/common/find.dart +++ b/packages/flutter_driver/lib/src/common/find.dart @@ -185,14 +185,14 @@ class BySemanticsLabel extends SerializableFinder { @override Map serialize() { if (label is RegExp) { - final RegExp regExp = label; + final RegExp regExp = label as RegExp; return super.serialize()..addAll({ 'label': regExp.pattern, 'isRegExp': 'true', }); } else { return super.serialize()..addAll({ - 'label': label, + 'label': label as String, }); } } @@ -351,9 +351,9 @@ class Descendant extends SerializableFinder { /// Deserializes the finder from JSON generated by [serialize]. static Descendant deserialize(Map json) { final Map jsonOfMatcher = - Map.from(jsonDecode(json['of'])); + Map.from(jsonDecode(json['of']) as Map); final Map jsonMatchingMatcher = - Map.from(jsonDecode(json['matching'])); + Map.from(jsonDecode(json['matching']) as Map); return Descendant( of: SerializableFinder.deserialize(jsonOfMatcher), matching: SerializableFinder.deserialize(jsonMatchingMatcher), @@ -406,9 +406,9 @@ class Ancestor extends SerializableFinder { /// Deserializes the finder from JSON generated by [serialize]. static Ancestor deserialize(Map json) { final Map jsonOfMatcher = - Map.from(jsonDecode(json['of'])); + Map.from(jsonDecode(json['of']) as Map); final Map jsonMatchingMatcher = - Map.from(jsonDecode(json['matching'])); + Map.from(jsonDecode(json['matching']) as Map); return Ancestor( of: SerializableFinder.deserialize(jsonOfMatcher), matching: SerializableFinder.deserialize(jsonMatchingMatcher), @@ -454,7 +454,7 @@ class GetSemanticsIdResult extends Result { /// Deserializes this result from JSON. static GetSemanticsIdResult fromJson(Map json) { - return GetSemanticsIdResult(json['id']); + return GetSemanticsIdResult(json['id'] as int); } @override diff --git a/packages/flutter_driver/lib/src/common/fuchsia_compat.dart b/packages/flutter_driver/lib/src/common/fuchsia_compat.dart index 9bf1880aa5..5875d476df 100644 --- a/packages/flutter_driver/lib/src/common/fuchsia_compat.dart +++ b/packages/flutter_driver/lib/src/common/fuchsia_compat.dart @@ -58,7 +58,7 @@ class _DummySshCommandRunner implements SshCommandRunner { // will wait indefinitely for the `out` directory to be serviced, causing // a deadlock. final ProcessResult r = await Process.run(exe, args); - return r.stdout.split('\n'); + return (r.stdout as String).split('\n'); } on ProcessException catch (e) { _log("Error running '$command': $e"); } diff --git a/packages/flutter_driver/lib/src/common/geometry.dart b/packages/flutter_driver/lib/src/common/geometry.dart index 84ad527867..3d3ead6b50 100644 --- a/packages/flutter_driver/lib/src/common/geometry.dart +++ b/packages/flutter_driver/lib/src/common/geometry.dart @@ -36,7 +36,7 @@ class GetOffset extends CommandWithTarget { GetOffset(SerializableFinder finder, this.offsetType, { Duration timeout }) : super(finder, timeout: timeout); /// Deserializes this command from the value generated by [serialize]. - GetOffset.deserialize(Map json) + GetOffset.deserialize(Map json) : offsetType = _offsetTypeIndex.lookupBySimpleName(json['offsetType']), super.deserialize(json); @@ -75,8 +75,8 @@ class GetOffsetResult extends Result { /// Deserializes the result from JSON. static GetOffsetResult fromJson(Map json) { return GetOffsetResult( - dx: json['dx'], - dy: json['dy'], + dx: json['dx'] as double, + dy: json['dy'] as double, ); } diff --git a/packages/flutter_driver/lib/src/common/health.dart b/packages/flutter_driver/lib/src/common/health.dart index 29c3c99d70..34a7879efc 100644 --- a/packages/flutter_driver/lib/src/common/health.dart +++ b/packages/flutter_driver/lib/src/common/health.dart @@ -46,7 +46,7 @@ class Health extends Result { /// Deserializes the result from JSON. static Health fromJson(Map json) { - return Health(_healthStatusIndex.lookupBySimpleName(json['status'])); + return Health(_healthStatusIndex.lookupBySimpleName(json['status'] as String)); } @override diff --git a/packages/flutter_driver/lib/src/common/render_tree.dart b/packages/flutter_driver/lib/src/common/render_tree.dart index 457def5c6a..a0884cc125 100644 --- a/packages/flutter_driver/lib/src/common/render_tree.dart +++ b/packages/flutter_driver/lib/src/common/render_tree.dart @@ -27,7 +27,7 @@ class RenderTree extends Result { /// Deserializes the result from JSON. static RenderTree fromJson(Map json) { - return RenderTree(json['tree']); + return RenderTree(json['tree'] as String); } @override diff --git a/packages/flutter_driver/lib/src/common/request_data.dart b/packages/flutter_driver/lib/src/common/request_data.dart index bbef6db479..c1ac12394e 100644 --- a/packages/flutter_driver/lib/src/common/request_data.dart +++ b/packages/flutter_driver/lib/src/common/request_data.dart @@ -40,7 +40,7 @@ class RequestDataResult extends Result { /// Deserializes the result from JSON. static RequestDataResult fromJson(Map json) { - return RequestDataResult(json['message']); + return RequestDataResult(json['message'] as String); } @override diff --git a/packages/flutter_driver/lib/src/common/semantics.dart b/packages/flutter_driver/lib/src/common/semantics.dart index d57d4c1829..400072fbee 100644 --- a/packages/flutter_driver/lib/src/common/semantics.dart +++ b/packages/flutter_driver/lib/src/common/semantics.dart @@ -37,7 +37,7 @@ class SetSemanticsResult extends Result { /// Deserializes this result from JSON. static SetSemanticsResult fromJson(Map json) { - return SetSemanticsResult(json['changedState']); + return SetSemanticsResult(json['changedState'] as bool); } @override diff --git a/packages/flutter_driver/lib/src/common/text.dart b/packages/flutter_driver/lib/src/common/text.dart index 88e0811d55..edec6a244b 100644 --- a/packages/flutter_driver/lib/src/common/text.dart +++ b/packages/flutter_driver/lib/src/common/text.dart @@ -11,7 +11,7 @@ class GetText extends CommandWithTarget { GetText(SerializableFinder finder, { Duration timeout }) : super(finder, timeout: timeout); /// Deserializes this command from the value generated by [serialize]. - GetText.deserialize(Map json) : super.deserialize(json); + GetText.deserialize(Map json) : super.deserialize(json); @override String get kind => 'get_text'; @@ -27,7 +27,7 @@ class GetTextResult extends Result { /// Deserializes the result from JSON. static GetTextResult fromJson(Map json) { - return GetTextResult(json['text']); + return GetTextResult(json['text'] as String); } @override @@ -42,7 +42,7 @@ class EnterText extends Command { const EnterText(this.text, { Duration timeout }) : super(timeout: timeout); /// Deserializes this command from the value generated by [serialize]. - EnterText.deserialize(Map json) + EnterText.deserialize(Map json) : text = json['text'], super.deserialize(json); @@ -78,7 +78,7 @@ class SetTextEntryEmulation extends Command { const SetTextEntryEmulation(this.enabled, { Duration timeout }) : super(timeout: timeout); /// Deserializes this command from the value generated by [serialize]. - SetTextEntryEmulation.deserialize(Map json) + SetTextEntryEmulation.deserialize(Map json) : enabled = json['enabled'] == 'true', super.deserialize(json); diff --git a/packages/flutter_driver/lib/src/common/wait.dart b/packages/flutter_driver/lib/src/common/wait.dart index a7dac7a26f..d5ba23d470 100644 --- a/packages/flutter_driver/lib/src/common/wait.dart +++ b/packages/flutter_driver/lib/src/common/wait.dart @@ -159,7 +159,7 @@ class NoTransientCallbacks extends SerializableWaitCondition { /// given JSON map. /// /// The [json] argument must not be null. - factory NoTransientCallbacks.deserialize(Map json) { + factory NoTransientCallbacks.deserialize(Map json) { assert(json != null); if (json['conditionName'] != 'NoTransientCallbacksCondition') throw SerializationException('Error occurred during deserializing the NoTransientCallbacksCondition JSON string: $json'); @@ -179,7 +179,7 @@ class NoPendingFrame extends SerializableWaitCondition { /// JSON map. /// /// The [json] argument must not be null. - factory NoPendingFrame.deserialize(Map json) { + factory NoPendingFrame.deserialize(Map json) { assert(json != null); if (json['conditionName'] != 'NoPendingFrameCondition') throw SerializationException('Error occurred during deserializing the NoPendingFrameCondition JSON string: $json'); @@ -199,7 +199,7 @@ class FirstFrameRasterized extends SerializableWaitCondition { /// given JSON map. /// /// The [json] argument must not be null. - factory FirstFrameRasterized.deserialize(Map json) { + factory FirstFrameRasterized.deserialize(Map json) { assert(json != null); if (json['conditionName'] != 'FirstFrameRasterizedCondition') throw SerializationException('Error occurred during deserializing the FirstFrameRasterizedCondition JSON string: $json'); @@ -219,7 +219,7 @@ class NoPendingPlatformMessages extends SerializableWaitCondition { /// given JSON map. /// /// The [json] argument must not be null. - factory NoPendingPlatformMessages.deserialize(Map json) { + factory NoPendingPlatformMessages.deserialize(Map json) { assert(json != null); if (json['conditionName'] != 'NoPendingPlatformMessagesCondition') throw SerializationException('Error occurred during deserializing the NoPendingPlatformMessagesCondition JSON string: $json'); @@ -242,7 +242,7 @@ class CombinedCondition extends SerializableWaitCondition { /// given JSON map. /// /// The [jsonMap] argument must not be null. - factory CombinedCondition.deserialize(Map jsonMap) { + factory CombinedCondition.deserialize(Map jsonMap) { assert(jsonMap != null); if (jsonMap['conditionName'] != 'CombinedCondition') throw SerializationException('Error occurred during deserializing the CombinedCondition JSON string: $jsonMap'); @@ -252,7 +252,7 @@ class CombinedCondition extends SerializableWaitCondition { final List conditions = []; for (Map condition in json.decode(jsonMap['conditions'])) { - conditions.add(_deserialize(condition)); + conditions.add(_deserialize(condition.cast())); } return CombinedCondition(conditions); } @@ -279,7 +279,7 @@ class CombinedCondition extends SerializableWaitCondition { /// Parses a [SerializableWaitCondition] or its subclass from the given [json] map. /// /// The [json] argument must not be null. -SerializableWaitCondition _deserialize(Map json) { +SerializableWaitCondition _deserialize(Map json) { assert(json != null); final String conditionName = json['conditionName']; switch (conditionName) { diff --git a/packages/flutter_driver/lib/src/driver/driver.dart b/packages/flutter_driver/lib/src/driver/driver.dart index e80accd5f4..71a1d7d94b 100644 --- a/packages/flutter_driver/lib/src/driver/driver.dart +++ b/packages/flutter_driver/lib/src/driver/driver.dart @@ -436,7 +436,7 @@ class FlutterDriver { final Future> future = appIsolate.invokeExtension( _flutterExtensionMethodName, serialized, - ).then>((Object value) => value); + ).then>((Object value) => value as Map); response = await _warnIfSlow>( future: future, timeout: command.timeout ?? kUnusuallyLongTimeout, @@ -450,9 +450,9 @@ class FlutterDriver { stackTrace, ); } - if (response['isError']) + if (response['isError'] as bool) throw DriverError('Error in Flutter application: ${response['response']}'); - return response['response']; + return response['response'] as Map; } void _logCommunication(String message) { @@ -850,8 +850,8 @@ class FlutterDriver { // and a source of flakes. await Future.delayed(const Duration(seconds: 2)); - final Map result = await _peer.sendRequest('_flutter.screenshot'); - return base64.decode(result['screenshot']); + final Map result = await _peer.sendRequest('_flutter.screenshot') as Map; + return base64.decode(result['screenshot'] as String); } /// Returns the Flags set in the Dart VM as JSON. @@ -875,9 +875,9 @@ class FlutterDriver { /// [getFlagList]: https://github.com/dart-lang/sdk/blob/master/runtime/vm/service/service.md#getflaglist Future>> getVmFlags() async { await _restorePeerConnectionIfNeeded(); - final Map result = await _peer.sendRequest('getFlagList'); + final Map result = await _peer.sendRequest('getFlagList') as Map; return result != null - ? result['flags'].cast>() + ? (result['flags'] as List).cast>() : const >[]; } @@ -924,7 +924,7 @@ class FlutterDriver { timeout: timeout, message: 'VM is taking an unusually long time to respond to being told to stop tracing...', ); - return Timeline.fromJson(await _peer.sendRequest(_getVMTimelineMethodName)); + return Timeline.fromJson(await _peer.sendRequest(_getVMTimelineMethodName) as Map); } catch (error, stackTrace) { throw DriverError( 'Failed to stop tracing due to remote error', @@ -1239,10 +1239,9 @@ class DriverOffset { @override bool operator ==(dynamic other) { - if (other is! DriverOffset) - return false; - final DriverOffset typedOther = other; - return dx == typedOther.dx && dy == typedOther.dy; + return other is DriverOffset + && other.dx == dx + && other.dy == dy; } @override diff --git a/packages/flutter_driver/lib/src/driver/timeline.dart b/packages/flutter_driver/lib/src/driver/timeline.dart index 31ad14c23b..963379cc3f 100644 --- a/packages/flutter_driver/lib/src/driver/timeline.dart +++ b/packages/flutter_driver/lib/src/driver/timeline.dart @@ -29,20 +29,20 @@ class TimelineEvent { factory TimelineEvent(Map json) { return TimelineEvent._( json, - json['name'], - json['cat'], - json['ph'], - json['pid'], - json['tid'], + json['name'] as String, + json['cat'] as String, + json['ph'] as String, + json['pid'] as int, + json['tid'] as int, json['dur'] != null - ? Duration(microseconds: json['dur']) + ? Duration(microseconds: json['dur'] as int) : null, json['tdur'] != null - ? Duration(microseconds: json['tdur']) + ? Duration(microseconds: json['tdur'] as int) : null, - json['ts'], - json['tts'], - json['args'], + json['ts'] as int, + json['tts'] as int, + json['args'] as Map, ); } @@ -122,7 +122,7 @@ class TimelineEvent { } List _parseEvents(Map json) { - final List jsonEvents = json['traceEvents']; + final List jsonEvents = json['traceEvents'] as List; if (jsonEvents == null) return null; diff --git a/packages/flutter_driver/lib/src/extension/extension.dart b/packages/flutter_driver/lib/src/extension/extension.dart index b9b5a36c31..f883b7b77a 100644 --- a/packages/flutter_driver/lib/src/extension/extension.dart +++ b/packages/flutter_driver/lib/src/extension/extension.dart @@ -152,14 +152,14 @@ class FlutterDriverExtension { }); _finders.addAll({ - 'ByText': (SerializableFinder finder) => _createByTextFinder(finder), - 'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder), - 'BySemanticsLabel': (SerializableFinder finder) => _createBySemanticsLabelFinder(finder), - 'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder), - 'ByType': (SerializableFinder finder) => _createByTypeFinder(finder), + 'ByText': (SerializableFinder finder) => _createByTextFinder(finder as ByText), + 'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder as ByTooltipMessage), + 'BySemanticsLabel': (SerializableFinder finder) => _createBySemanticsLabelFinder(finder as BySemanticsLabel), + 'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder as ByValueKey), + 'ByType': (SerializableFinder finder) => _createByTypeFinder(finder as ByType), 'PageBack': (SerializableFinder finder) => _createPageBackFinder(), - 'Ancestor': (SerializableFinder finder) => _createAncestorFinder(finder), - 'Descendant': (SerializableFinder finder) => _createDescendantFinder(finder), + 'Ancestor': (SerializableFinder finder) => _createAncestorFinder(finder as Ancestor), + 'Descendant': (SerializableFinder finder) => _createDescendantFinder(finder as Descendant), }); } @@ -314,9 +314,9 @@ class FlutterDriverExtension { Finder _createByValueKeyFinder(ByValueKey arguments) { switch (arguments.keyValueType) { case 'int': - return find.byKey(ValueKey(arguments.keyValue)); + return find.byKey(ValueKey(arguments.keyValue as int)); case 'String': - return find.byKey(ValueKey(arguments.keyValue)); + return find.byKey(ValueKey(arguments.keyValue as String)); default: throw 'Unsupported ByValueKey type: ${arguments.keyValueType}'; } @@ -367,7 +367,7 @@ class FlutterDriverExtension { } Future _tap(Command command) async { - final Tap tapCommand = command; + final Tap tapCommand = command as Tap; final Finder computedFinder = await _waitForElement( _createFinder(tapCommand.finder).hitTestable() ); @@ -376,20 +376,20 @@ class FlutterDriverExtension { } Future _waitFor(Command command) async { - final WaitFor waitForCommand = command; + final WaitFor waitForCommand = command as WaitFor; await _waitForElement(_createFinder(waitForCommand.finder)); return const WaitForResult(); } Future _waitForAbsent(Command command) async { - final WaitForAbsent waitForAbsentCommand = command; + final WaitForAbsent waitForAbsentCommand = command as WaitForAbsent; await _waitForAbsentElement(_createFinder(waitForAbsentCommand.finder)); return const WaitForAbsentResult(); } Future _waitForCondition(Command command) async { assert(command != null); - final WaitForCondition waitForConditionCommand = command; + final WaitForCondition waitForConditionCommand = command as WaitForCondition; final WaitCondition condition = deserializeCondition(waitForConditionCommand.condition); await condition.wait(); return null; @@ -437,7 +437,7 @@ class FlutterDriverExtension { } Future _getSemanticsId(Command command) async { - final GetSemanticsId semanticsCommand = command; + final GetSemanticsId semanticsCommand = command as GetSemanticsId; final Finder target = await _waitForElement(_createFinder(semanticsCommand.finder)); final Iterable elements = target.evaluate(); if (elements.length > 1) { @@ -448,7 +448,7 @@ class FlutterDriverExtension { SemanticsNode node; while (renderObject != null && node == null) { node = renderObject.debugSemantics; - renderObject = renderObject.parent; + renderObject = renderObject.parent as RenderObject; } if (node == null) throw StateError('No semantics data found'); @@ -456,10 +456,10 @@ class FlutterDriverExtension { } Future _getOffset(Command command) async { - final GetOffset getOffsetCommand = command; + final GetOffset getOffsetCommand = command as GetOffset; final Finder finder = await _waitForElement(_createFinder(getOffsetCommand.finder)); final Element element = finder.evaluate().single; - final RenderBox box = element.renderObject; + final RenderBox box = element.renderObject as RenderBox; Offset localPoint; switch (getOffsetCommand.offsetType) { case OffsetType.topLeft: @@ -483,7 +483,7 @@ class FlutterDriverExtension { } Future _getDiagnosticsTree(Command command) async { - final GetDiagnosticsTree diagnosticsCommand = command; + final GetDiagnosticsTree diagnosticsCommand = command as GetDiagnosticsTree; final Finder finder = await _waitForElement(_createFinder(diagnosticsCommand.finder)); final Element element = finder.evaluate().single; DiagnosticsNode diagnosticsNode; @@ -502,7 +502,7 @@ class FlutterDriverExtension { } Future _scroll(Command command) async { - final Scroll scrollCommand = command; + final Scroll scrollCommand = command as Scroll; final Finder target = await _waitForElement(_createFinder(scrollCommand.finder)); final int totalMoves = scrollCommand.duration.inMicroseconds * scrollCommand.frequency ~/ Duration.microsecondsPerSecond; final Offset delta = Offset(scrollCommand.dx, scrollCommand.dy) / totalMoves.toDouble(); @@ -526,22 +526,22 @@ class FlutterDriverExtension { } Future _scrollIntoView(Command command) async { - final ScrollIntoView scrollIntoViewCommand = command; + final ScrollIntoView scrollIntoViewCommand = command as ScrollIntoView; final Finder target = await _waitForElement(_createFinder(scrollIntoViewCommand.finder)); await Scrollable.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100), alignment: scrollIntoViewCommand.alignment ?? 0.0); return const ScrollResult(); } Future _getText(Command command) async { - final GetText getTextCommand = command; + final GetText getTextCommand = command as GetText; final Finder target = await _waitForElement(_createFinder(getTextCommand.finder)); // TODO(yjbanov): support more ways to read text - final Text text = target.evaluate().single.widget; + final Text text = target.evaluate().single.widget as Text; return GetTextResult(text.data); } Future _setTextEntryEmulation(Command command) async { - final SetTextEntryEmulation setTextEntryEmulationCommand = command; + final SetTextEntryEmulation setTextEntryEmulationCommand = command as SetTextEntryEmulation; if (setTextEntryEmulationCommand.enabled) { _testTextInput.register(); } else { @@ -555,18 +555,18 @@ class FlutterDriverExtension { throw 'Unable to fulfill `FlutterDriver.enterText`. Text emulation is ' 'disabled. You can enable it using `FlutterDriver.setTextEntryEmulation`.'; } - final EnterText enterTextCommand = command; + final EnterText enterTextCommand = command as EnterText; _testTextInput.enterText(enterTextCommand.text); return const EnterTextResult(); } Future _requestData(Command command) async { - final RequestData requestDataCommand = command; + final RequestData requestDataCommand = command as RequestData; return RequestDataResult(_requestDataHandler == null ? 'No requestData Extension registered' : await _requestDataHandler(requestDataCommand.message)); } Future _setFrameSync(Command command) async { - final SetFrameSync setFrameSyncCommand = command; + final SetFrameSync setFrameSyncCommand = command as SetFrameSync; _frameSync = setFrameSyncCommand.enabled; return const SetFrameSyncResult(); } @@ -575,7 +575,7 @@ class FlutterDriverExtension { bool get _semanticsIsEnabled => RendererBinding.instance.pipelineOwner.semanticsOwner != null; Future _setSemantics(Command command) async { - final SetSemantics setSemanticsCommand = command; + final SetSemantics setSemanticsCommand = command as SetSemantics; final bool semanticsWasEnabled = _semanticsIsEnabled; if (setSemanticsCommand.enabled && _semantics == null) { _semantics = RendererBinding.instance.pipelineOwner.ensureSemantics(); diff --git a/packages/flutter_driver/lib/src/extension/wait_conditions.dart b/packages/flutter_driver/lib/src/extension/wait_conditions.dart index c181495bef..336d48ceda 100644 --- a/packages/flutter_driver/lib/src/extension/wait_conditions.dart +++ b/packages/flutter_driver/lib/src/extension/wait_conditions.dart @@ -132,13 +132,13 @@ class _InternalNoPendingPlatformMessagesCondition implements WaitCondition { @override bool get condition { - final TestDefaultBinaryMessenger binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger; + final TestDefaultBinaryMessenger binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger as TestDefaultBinaryMessenger; return binaryMessenger.pendingMessageCount == 0; } @override Future wait() async { - final TestDefaultBinaryMessenger binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger; + final TestDefaultBinaryMessenger binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger as TestDefaultBinaryMessenger; while (!condition) { await binaryMessenger.platformMessagesFinished; } @@ -163,7 +163,7 @@ class _InternalCombinedCondition implements WaitCondition { assert(condition != null); if (condition.conditionName != 'CombinedCondition') throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}'); - final CombinedCondition combinedCondition = condition; + final CombinedCondition combinedCondition = condition as CombinedCondition; if (combinedCondition.conditions == null) { return const _InternalCombinedCondition([]); } diff --git a/packages/flutter_driver/test/src/extension_test.dart b/packages/flutter_driver/test/src/extension_test.dart index 9600e6429f..de66790231 100644 --- a/packages/flutter_driver/test/src/extension_test.dart +++ b/packages/flutter_driver/test/src/extension_test.dart @@ -83,7 +83,8 @@ void main() { testWidgets('handler', (WidgetTester tester) async { expect(log, isEmpty); - final dynamic result = RequestDataResult.fromJson((await extension.call(const RequestData('hello').serialize()))['response']); + final Map response = await extension.call(const RequestData('hello').serialize()); + final RequestDataResult result = RequestDataResult.fromJson(response['response'] as Map); expect(log, ['hello']); expect(result.message, '1'); }); @@ -471,8 +472,9 @@ void main() { await tester.pumpWidget( const Text('hello', textDirection: TextDirection.ltr)); - final Map arguments = GetSemanticsId(const ByText('hello')).serialize(); - final GetSemanticsIdResult result = GetSemanticsIdResult.fromJson((await extension.call(arguments))['response']); + final Map arguments = GetSemanticsId(const ByText('hello')).serialize(); + final Map response = await extension.call(arguments); + final GetSemanticsIdResult result = GetSemanticsIdResult.fromJson(response['response'] as Map); expect(result.id, 1); semantics.dispose(); @@ -482,8 +484,8 @@ void main() { await tester.pumpWidget( const Text('hello', textDirection: TextDirection.ltr)); - final Map arguments = GetSemanticsId(const ByText('hello')).serialize(); - final Map response = await extension.call(arguments); + final Map arguments = GetSemanticsId(const ByText('hello')).serialize(); + final Map response = await extension.call(arguments); expect(response['isError'], true); expect(response['response'], contains('Bad state: No semantics data found')); @@ -501,8 +503,8 @@ void main() { ), ); - final Map arguments = GetSemanticsId(const ByText('hello')).serialize(); - final Map response = await extension.call(arguments); + final Map arguments = GetSemanticsId(const ByText('hello')).serialize(); + final Map response = await extension.call(arguments); expect(response['isError'], true); expect(response['response'], contains('Bad state: Found more than one element with the same ID')); @@ -514,8 +516,9 @@ void main() { final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true); Future getOffset(OffsetType offset) async { - final Map arguments = GetOffset(ByValueKey(1), offset).serialize(); - final GetOffsetResult result = GetOffsetResult.fromJson((await extension.call(arguments))['response']); + final Map arguments = GetOffset(ByValueKey(1), offset).serialize(); + final Map response = await extension.call(arguments); + final GetOffsetResult result = GetOffsetResult.fromJson(response['response'] as Map); return Offset(result.dx, result.dy); } @@ -545,16 +548,16 @@ void main() { final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true); Future getDescendantText({ String of, bool matchRoot = false}) async { - final Map arguments = GetText(Descendant( + final Map arguments = GetText(Descendant( of: ByValueKey(of), matching: ByValueKey('text2'), matchRoot: matchRoot, ), timeout: const Duration(seconds: 1)).serialize(); final Map result = await extension.call(arguments); - if (result['isError']) { + if (result['isError'] as bool) { return null; } - return GetTextResult.fromJson(result['response']).text; + return GetTextResult.fromJson(result['response'] as Map).text; } await tester.pumpWidget( @@ -590,16 +593,16 @@ void main() { final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true); Future getDescendantText() async { - final Map arguments = GetText(Descendant( + final Map arguments = GetText(Descendant( of: ByValueKey('column'), matching: const ByType('Text'), firstMatchOnly: true, ), timeout: const Duration(seconds: 1)).serialize(); final Map result = await extension.call(arguments); - if (result['isError']) { + if (result['isError'] as bool) { return null; } - return GetTextResult.fromJson(result['response']).text; + return GetTextResult.fromJson(result['response'] as Map).text; } await tester.pumpWidget( @@ -624,16 +627,16 @@ void main() { final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true); Future getAncestorTopLeft({ String of, String matching, bool matchRoot = false}) async { - final Map arguments = GetOffset(Ancestor( + final Map arguments = GetOffset(Ancestor( of: ByValueKey(of), matching: ByValueKey(matching), matchRoot: matchRoot, ), OffsetType.topLeft, timeout: const Duration(seconds: 1)).serialize(); final Map response = await extension.call(arguments); - if (response['isError']) { + if (response['isError'] as bool) { return null; } - final GetOffsetResult result = GetOffsetResult.fromJson(response['response']); + final GetOffsetResult result = GetOffsetResult.fromJson(response['response'] as Map); return Offset(result.dx, result.dy); } @@ -694,16 +697,16 @@ void main() { final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true); Future getAncestorTopLeft() async { - final Map arguments = GetOffset(Ancestor( + final Map arguments = GetOffset(Ancestor( of: ByValueKey('leaf'), matching: const ByType('Container'), firstMatchOnly: true, ), OffsetType.topLeft, timeout: const Duration(seconds: 1)).serialize(); final Map response = await extension.call(arguments); - if (response['isError']) { + if (response['isError'] as bool) { return null; } - final GetOffsetResult result = GetOffsetResult.fromJson(response['response']); + final GetOffsetResult result = GetOffsetResult.fromJson(response['response'] as Map); return Offset(result.dx, result.dy); } @@ -742,8 +745,9 @@ void main() { final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true); Future> getDiagnosticsTree(DiagnosticsType type, SerializableFinder finder, { int depth = 0, bool properties = true }) async { - final Map arguments = GetDiagnosticsTree(finder, type, subtreeDepth: depth, includeProperties: properties).serialize(); - final DiagnosticsTreeResult result = DiagnosticsTreeResult((await extension.call(arguments))['response']); + final Map arguments = GetDiagnosticsTree(finder, type, subtreeDepth: depth, includeProperties: properties).serialize(); + final Map response = await extension.call(arguments); + final DiagnosticsTreeResult result = DiagnosticsTreeResult(response['response'] as Map); return result.json; } @@ -761,7 +765,7 @@ void main() { expect(result['children'], isNull); // depth: 0 expect(result['widgetRuntimeType'], 'Text'); - List> properties = result['properties']; + List> properties = (result['properties'] as List).cast>(); Map stringProperty = properties.singleWhere((Map property) => property['name'] == 'data'); expect(stringProperty['description'], '"Hello World"'); expect(stringProperty['propertyType'], 'String'); @@ -771,11 +775,11 @@ void main() { expect(result['properties'], isNull); // properties: false result = await getDiagnosticsTree(DiagnosticsType.widget, ByValueKey('Text'), depth: 1); - List> children = result['children']; + List> children = (result['children'] as List).cast>(); expect(children.single['children'], isNull); result = await getDiagnosticsTree(DiagnosticsType.widget, ByValueKey('Text'), depth: 100); - children = result['children']; + children = (result['children'] as List).cast>(); expect(children.single['children'], isEmpty); // RenderObject @@ -789,17 +793,17 @@ void main() { expect(result['description'], startsWith('RenderParagraph')); result = await getDiagnosticsTree(DiagnosticsType.renderObject, ByValueKey('Text'), depth: 1); - children = result['children']; + children = (result['children'] as List).cast>(); final Map textSpan = children.single; expect(textSpan['description'], 'TextSpan'); - properties = textSpan['properties']; + properties = (textSpan['properties'] as List).cast>(); stringProperty = properties.singleWhere((Map property) => property['name'] == 'text'); expect(stringProperty['description'], '"Hello World"'); expect(stringProperty['propertyType'], 'String'); expect(children.single['children'], isNull); result = await getDiagnosticsTree(DiagnosticsType.renderObject, ByValueKey('Text'), depth: 100); - children = result['children']; + children = (result['children'] as List).cast>(); expect(children.single['children'], isEmpty); });