fetchAllContacts method

Future<List<EMContact>> fetchAllContacts()

~english Gets all contacts from the server.

Return The contact list.

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

~chinese 从服务器获取所有的好友。

Return 好友列表。

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

Implementation

Future<List<EMContact>> fetchAllContacts() async {
  try {
    Map result = await Client.instance.contactManager
        .callNativeMethod(ChatMethodKeys.fetchAllContacts);
    EMError.hasErrorFromResult(result);
    List<EMContact> list = [];
    result[ChatMethodKeys.fetchAllContacts]?.forEach((element) {
      list.add(EMContact.fromJson(element));
    });
    return list;
  } catch (e) {
    rethrow;
  }
}