I am using contact_service plugin to manage users’ contact data in my flutter app.
i am getting 2 major issues while using this plugin
1. when I am updating old contact, no errors are coming but the mobile number is getting removed from the old contact and sometimes its been getting deleted.
my code is like this
Contact? duplicateContact = <old contact>;
duplicateContact.givenName = <new name>;
duplicateContact.company = <company name>;
duplicateContact.phones = [Item(value: mobile, label: "mobile")];
await ContactsService.updateContact(contact);
so i this process is in loop as i want to update multiple contacts,but contact is not getting updated, instead of either mobile number field will be updated as empty or the whole contact will be get deleted.
so I don’t know what is happening wrong with the contact update, I find out many things but nothing is working
2. I am trying save multiple contacts at a time using a loop, so I add the contact save code in loop as mention below
for (var element in contactData) {
final contact = Contact(
phones: [Item(value: <mobileNo>)],
givenName: <name>,
company: <companyName>,
);
await ContactsService.addContact(contact);
}
here, I am getting a very weird issue, In this loop, I am trying to add contacts for about 50 people, but one person’s mobile number is combined with another person’s contact. some times 3 or 4 different person’s mobile numbers are saved in one contact.
2
Answers
I think you have forgotten some major steps to complete your code:
Otherwise try to use this plugin instead flutter_contact.
As per my understanding
contact_service
you initialise correctly withiOS
&Android
permissions as per mentioned in documentation. so i believe that you are getting contact correctly.still verify once.For
contact update
you must need to addidentifier
as per documentation. also you need to usefuture
loop forasync
tasks.try like bellow code (tested in iOS):