QuisApp / flutter_contacts

MIT License
83 stars 138 forks source link

Adding contact to a group doesn't work when default contacts account is not iCloud on iOS #129

Open josiahyeow opened 1 year ago

josiahyeow commented 1 year ago

Adding a contact to a group doesn't work on IOS when the "Default Account" for contacts is not iCloud.

This contact is added to the group but is removed automatically shortly after it's added. I specifically tested using a Gmail default account.

Code example

 Group? group;
    group = (await FlutterContacts.getGroups())
        .firstWhereOrNull((element) => element.name == 'My group');

    group ??= await FlutterContacts.insertGroup(Group('mygroup', 'My Group'));

    final newContact = Contact()
      ..name.first = contact.firstName
      ..name.last = contact.lastName
      ..phones = [if (contact.phone != null) Phone(contact.phone!)]
      ..emails = [if (contact.email != null) Email(contact.email!)]
      ..notes = [if (contact.notes != null) Note(contact.notes!)];

    final insertedContact = await newContact.insert();
    insertedContact.groups.add(group);
    insertedContact.update(withGroups: true);