I am trying to update my single contact data using flutter contact_service dart package. I am new in flutter programming that's why don't understand that how i can do that. that' my code.
enter code here
await ContactsService.updateContact(
Contact(displayName: "yello", phones: abcd))
.catchError((onError) {
print(onError.toString());
});
try this
/*this line fetches the contact whose familyName(last name) is "Jackson", incase
if there's multiple contact with the same familyName then it'll select first one */
Contact contactToUpdate = _contacts
.toList()
.firstWhere((contact) => contact.familyName.startsWith("Jackson"));
//this line updates the givenName(first name) of fetched contact to "Michael"
contactToUpdate.givenName = 'Michael';
await ContactsService.updateContact(contactToUpdate);
Iterable<Contact> UpdatedList = await ContactsService.getContacts(
query: 'Updated Phone',
withThumbnails: false,
photoHighResolution: false);
if (Updated.length != 0) {
print('found');
Contact UpdatedContact = Updated.first;
if (UpdatedContact.phones.first.value != '07938422874') {
print('changing contact');
UpdatedContact.phones = [Item(label: 'mobile', value: '07938422874')];
UpdatedContact.displayName = 'Antony Leons'
await ContactsService.updateContact(UpdatedContact);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.