addGroupContact method

dynamic addGroupContact(
  1. GroupContactsModel? item
)

Implementation

addGroupContact(GroupContactsModel? item) {
  try {
    var isSelected = false;
    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 ((item.toString() == groupContact.toString())) {
        isSelected = true;
        break;
      } else {
        isSelected = false;
      }
    }

    if (length <= 25 && !isSelected) {
      selectedGroupContacts.add(item);
    }

    if (item!.contactType == ContactsType.CONTACT) {
      length++;
    } else if (item.contactType == ContactsType.GROUP) {
      length += item.group!.members!.length;
    }

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