removeGroupContact method

dynamic removeGroupContact(
  1. GroupContactsModel? item
)

Implementation

removeGroupContact(GroupContactsModel? item) async {
  try {
    length = 0;
    if (selectedGroupContacts.isNotEmpty) {
      selectedGroupContacts.forEach((groupContact) {
        if (groupContact!.contactType == ContactsType.CONTACT) {
          length++;
        } else if (groupContact.contactType == ContactsType.GROUP) {
          length = length + groupContact.group!.members!.length;
        }
      });
    }

    // ignore: omit_local_variable_types
    for (GroupContactsModel? groupContact in selectedGroupContacts) {
      if ((groupContact.toString() == item.toString())) {
        var index = selectedGroupContacts.indexOf(groupContact);
        selectedGroupContacts.removeAt(index);
        break;
      }
    }
    if (item!.contactType == ContactsType.CONTACT) {
      length--;
    } else if (item.contactType == ContactsType.GROUP) {
      length -= item.group!.members!.length;
    }

    selectedContactsSink.add(selectedGroupContacts);
  } catch (e) {
    print(e);
  }
}