callExtension static method
can call any extension
can be used in extensions like Pin message, Save message,Tiny Url, Bitly etc
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<Map<String, dynamic>?> callExtension(String slug, String requestType, String endPoint, Map<String, dynamic>? body, {required Function(Map<String, dynamic> map)? onSuccess, required Function(CometChatException excep)? onError}) async {
try {
if (Platform.isIOS && endPoint.isNotEmpty && endPoint[0] == '/')
endPoint = endPoint.substring(1);
final result = await channel.invokeMethod('callExtension', {
'slug': slug,
'requestType': requestType,
'endPoint': endPoint,
'body': body,
});
var res;
if (Platform.isIOS) {
final _map = json.decode(result);
res = {'data': _map};
} else {
final map = json.decode(result);
res = Map<String, dynamic>.from(map);
}
if(onSuccess != null) onSuccess(res);
return res;
} on PlatformException catch (platformException) {
if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
} catch (e) {
debugPrint("Error: $e");
if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
}
return null;
}