invokeMethod<T> function
Implementation
Future<T> invokeMethod<T>(T factory(Map<String, dynamic> data), String methodName, Map<String, dynamic> args) async {
try {
logger.d("methodName: " + methodName + " args: " + args.toString());
final String json = await channel.invokeMethod(methodName, args);
logger.d("json: " + json);
return factory(jsonDecode(json));
} on PlatformException catch (e) {
final String code = e.code;
final String message = e.message ?? '';
if (code == "APIRequestError") {
final APIRequestError err = APIRequestError.fromJson(jsonDecode(message));
throw err;
} else if (code == "OAuthRequestError") {
final OAuthRequestError err = OAuthRequestError.fromJson(jsonDecode(message));
throw err;
} else {
final ProcessingError err = ProcessingError.fromJson(jsonDecode(message));
throw err;
}
}
}