searchFriend method

Future<List<FriendSearchInfo>> searchFriend(
  1. String text
)

查询好友,从姓名、昵称和账号中进行匹配

Implementation

Future<List<FriendSearchInfo>> searchFriend(String text) async {
  var contactList = await _getContactList();
  if (contactList?.isNotEmpty == true) {
    List<FriendSearchInfo> resultList = List.empty(growable: true);
    for (var contact in contactList!) {
      if (contact?.friend?.alias?.isNotEmpty == true) {
        var record = TextSearcher.search(contact!.friend!.alias!, text);
        if (record != null) {
          resultList.add(FriendSearchInfo(
              contact: contact, hitInfo: record, hitType: HitType.alias));
          continue;
        }
      }

      if (contact?.user.nick?.isNotEmpty == true) {
        var record = TextSearcher.search(contact!.user.nick!, text);
        if (record != null) {
          resultList.add(FriendSearchInfo(
              contact: contact, hitInfo: record, hitType: HitType.userName));
          continue;
        }
      }
      if (contact?.user.userId?.isNotEmpty == true) {
        var record = TextSearcher.search(contact!.user.userId!, text);
        if (record != null) {
          resultList.add(FriendSearchInfo(
              contact: contact, hitInfo: record, hitType: HitType.account));
          continue;
        }
      }
    }
    return resultList;
  } else {
    return List.empty();
  }
}