更改Flutter中与contacts_service的联系人的电话号码和显示名称

时间:2020-07-07 09:37:47

标签: flutter dart

我正在尝试使用flutter contact_service dart软件包更新我的单个联系人数据。我是Flutter编程的新手,这就是为什么不明白我该怎么做的原因。 那是我的代码。

enter code here
 await ContactsService.updateContact(
            Contact(displayName: "yello", phones: abcd))
        .catchError((onError) {
      print(onError.toString());
    });

2 个答案:

答案 0 :(得分:0)

尝试

/*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);

答案 1 :(得分:0)

      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);
    }
  }