Adds a type parameter to invokeMethod (and additional utility methods) (#26303)

This commit is contained in:
Jonah Williams
2019-01-10 13:21:03 -08:00
committed by GitHub
parent dca8d36d62
commit 83af6f48d6
15 changed files with 149 additions and 62 deletions

View File

@@ -26,7 +26,7 @@ Future<String> dataHandler(String message) async {
final Completer<String> completer = Completer<String>();
final int id = int.tryParse(message.split('#')[1]) ?? 0;
Future<void> completeSemantics([Object _]) async {
final dynamic result = await kSemanticsChannel.invokeMethod('getSemanticsNode', <String, dynamic>{
final dynamic result = await kSemanticsChannel.invokeMethod<dynamic>('getSemanticsNode', <String, dynamic>{
'id': id,
});
completer.complete(json.encode(result));

View File

@@ -125,15 +125,15 @@ class PlatformViewState extends State<PlatformViewPage> {
.cast<Map<dynamic, dynamic>>()
.map<Map<String, dynamic>>((Map<dynamic, dynamic> e) =>e.cast<String, dynamic>())
.toList();
await channel.invokeMethod('pipeFlutterViewEvents');
await viewChannel.invokeMethod('pipeTouchEvents');
await channel.invokeMethod<void>('pipeFlutterViewEvents');
await viewChannel.invokeMethod<void>('pipeTouchEvents');
print('replaying ${recordedEvents.length} motion events');
for (Map<String, dynamic> event in recordedEvents.reversed) {
await channel.invokeMethod('synthesizeEvent', event);
await channel.invokeMethod<void>('synthesizeEvent', event);
}
await channel.invokeMethod('stopFlutterViewEvents');
await viewChannel.invokeMethod('stopTouchEvents');
await channel.invokeMethod<void>('stopFlutterViewEvents');
await viewChannel.invokeMethod<void>('stopTouchEvents');
if (flutterViewEvents.length != embeddedViewEvents.length)
return 'Synthesized ${flutterViewEvents.length} events but the embedded view received ${embeddedViewEvents.length} events';
@@ -160,7 +160,7 @@ class PlatformViewState extends State<PlatformViewPage> {
}
Future<void> saveRecordedEvents(ByteData data, BuildContext context) async {
if (!await channel.invokeMethod('getStoragePermission')) {
if (!await channel.invokeMethod<bool>('getStoragePermission')) {
showMessage(
context, 'External storage permissions are required to save events');
return;
@@ -190,11 +190,11 @@ class PlatformViewState extends State<PlatformViewPage> {
}
void listenToFlutterViewEvents() {
channel.invokeMethod('pipeFlutterViewEvents');
viewChannel.invokeMethod('pipeTouchEvents');
channel.invokeMethod<void>('pipeFlutterViewEvents');
viewChannel.invokeMethod<void>('pipeTouchEvents');
Timer(const Duration(seconds: 3), () {
channel.invokeMethod('stopFlutterViewEvents');
viewChannel.invokeMethod('stopTouchEvents');
channel.invokeMethod<void>('stopFlutterViewEvents');
viewChannel.invokeMethod<void>('stopTouchEvents');
});
}

View File

@@ -67,7 +67,7 @@ Future<TestStepResult> _methodCallSuccessHandshake(
dynamic result = nothing;
dynamic error = nothing;
try {
result = await channel.invokeMethod('success', arguments);
result = await channel.invokeMethod<dynamic>('success', arguments);
} catch (e) {
error = e;
}
@@ -95,7 +95,7 @@ Future<TestStepResult> _methodCallErrorHandshake(
dynamic errorDetails = nothing;
dynamic error = nothing;
try {
error = await channel.invokeMethod('error', arguments);
error = await channel.invokeMethod<dynamic>('error', arguments);
} on PlatformException catch (e) {
errorDetails = e.details;
} catch (e) {
@@ -123,7 +123,7 @@ Future<TestStepResult> _methodCallNotImplementedHandshake(
dynamic result = nothing;
dynamic error = nothing;
try {
error = await channel.invokeMethod('notImplemented');
error = await channel.invokeMethod<dynamic>('notImplemented');
} on MissingPluginException {
result = null;
} catch (e) {

View File

@@ -47,11 +47,11 @@ Widget builds: $_widgetBuilds''';
_summary = 'Producing texture frames at .5x speed...';
_state = FrameState.slow;
_icon = Icons.stop;
channel.invokeMethod('start', _flutterFrameRate ~/ 2);
channel.invokeMethod<void>('start', _flutterFrameRate ~/ 2);
break;
case FrameState.slow:
debugPrint('Stopping .5x speed test...');
await channel.invokeMethod('stop');
await channel.invokeMethod<void>('stop');
await _summarizeStats();
_icon = Icons.fast_forward;
_state = FrameState.afterSlow;
@@ -62,11 +62,11 @@ Widget builds: $_widgetBuilds''';
_summary = 'Producing texture frames at 2x speed...';
_state = FrameState.fast;
_icon = Icons.stop;
channel.invokeMethod('start', (_flutterFrameRate * 2).toInt());
channel.invokeMethod<void>('start', (_flutterFrameRate * 2).toInt());
break;
case FrameState.fast:
debugPrint('Stopping 2x speed test...');
await channel.invokeMethod('stop');
await channel.invokeMethod<void>('stop');
await _summarizeStats();
_state = FrameState.afterFast;
_icon = Icons.replay;

View File

@@ -18,7 +18,7 @@ class _FlavorState extends State<Flavor> {
@override
void initState() {
super.initState();
const MethodChannel('flavor').invokeMethod('getFlavor').then((Object flavor) {
const MethodChannel('flavor').invokeMethod<String>('getFlavor').then((String flavor) {
setState(() {
_flavor = flavor;
});