callExtension static method

Future<Map<String, dynamic>?> callExtension(
  1. String slug,
  2. String requestType,
  3. String endPoint,
  4. Map<String, dynamic>? body, {
  5. required dynamic onSuccess(
    1. Map<String, dynamic> map
    )?,
  6. required dynamic onError(
    1. CometChatException excep
    )?,
})

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,
    });
    Map<String, dynamic> 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 (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}