onMethodCall method
Handles method calls from the native platform.
Implementation
Future<dynamic> onMethodCall(final MethodCall call) async {
try {
switch (call.method) {
case 'onPageChanged':
final args = call.arguments as String;
final locatorJson = json.decode(args) as Map<String, dynamic>;
final locator = Locator.fromJson(locatorJson);
ReadiumLog.d('onPageChanged $locator');
if (locator == null) {
ReadiumLog.w('onPageChanged received empty locator');
return null;
}
onPageChanged(locator);
return null;
case 'onExternalLinkActivated':
final link = call.arguments as String;
ReadiumLog.d('onExternalLinkActivated $link');
onExternalLinkActivated?.call(link);
return null;
case 'onTextSelected':
final args = call.arguments as String;
final eventJson = json.decode(args) as Map<String, dynamic>;
final event = TextSelectionEvent.fromJson(eventJson);
ReadiumLog.d('onTextSelected ${event.selectedText}');
onTextSelected?.call(event);
return null;
case 'onSelectionAction':
final args = call.arguments as String;
final eventJson = json.decode(args) as Map<String, dynamic>;
final event = SelectionActionEvent.fromJson(eventJson);
ReadiumLog.d('onSelectionAction ${event.actionId}');
onSelectionAction?.call(event);
return null;
case 'onDecorationInteraction':
final args = call.arguments as String;
final eventJson = json.decode(args) as Map<String, dynamic>;
final event = DecorationInteractionEvent.fromJson(eventJson);
ReadiumLog.d('onDecorationInteraction ${event.decorationId}');
onDecorationInteraction?.call(event);
return null;
default:
throw UnimplementedError('Unhandled call ${call.method}');
}
} on Object catch (e, st) {
ReadiumLog.e(e, data: call.method, stackTrace: st);
}
}