getContact method

Future<EMContact?> getContact({
  1. required String userId,
})

~english Gets contact by userId.

Param userId user id。

Return The contact.

Throws A description of the exception. See EMError. ~end

~chinese 获取联系人信息。

Param userId 联系人Id。

Return 联系下信息。

Throws 如果有方法调用的异常会在这里抛出,可以看到具体错误原因。请参见 EMError。 ~end

Implementation

Future<EMContact?> getContact({required String userId}) async {
  try {
    Map req = {'userId': userId};
    Map result = await Client.instance.contactManager
        .callNativeMethod(ChatMethodKeys.getContact, req);
    EMError.hasErrorFromResult(result);
    if (result.containsKey(ChatMethodKeys.getContact)) {
      return EMContact.fromJson(result[ChatMethodKeys.getContact]);
    } else {
      return null;
    }
  } catch (e) {
    rethrow;
  }
}