fetchContacts method

dynamic fetchContacts()

Implementation

fetchContacts() async {
  try {
    selectedContacts = [];
    contactList = [];
    allContactsList = [];
    contactList = await atContactImpl.listContacts();
    var tempContactList = <AtContact?>[...contactList];
    var range = contactList.length;
    for (var i = 0; i < range; i++) {
      allContactsList.add(contactList[i]!.atSign!);
      if (contactList[i]!.blocked!) {
        tempContactList.remove(contactList[i]);
      }
    }
    contactList = tempContactList;
    contactList.sort((a, b) {
      // ignore: omit_local_variable_types
      int? index = a?.atSign
          .toString()
          .substring(1)
          .compareTo(b!.atSign!.toString().substring(1));
      return index!;
    });

    compareContactListForUpdatedState();
    contactSink.add(baseContactList);
    return contactList;
  } catch (e) {
    print('error here => $e');
    return [];
  }
}