question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ContactsService.addContact to return id/displayName

See original GitHub issue

Not sure if possible with Android/iOS, but I would appreciate if ContactsService.addContact(contact) would:

  • set contact.id and contact.displayName as generated upon insertion
  • or return a Future<Contact> with the newly inserted contact including id and displayName

My use case is adding a new contact and then immediately switching to the contact update page (or rather going add -> detail -> update). To call ContactsService.updateContact(contact), contact.id must be set but I do not know it a priori after adding.

My current workaround is to reload the contact with ContactsService.getContacts(query = [contact.givenName, contact.middleName, contact.familyName].where((s) => s != null).join (" ")) but this fails e.g. if no familyName is set. Loading all contacts and then searching manually would also be possible but time consuming.

In summary, getting the id/displayName from addContact would be a much cleaner solution, and I would much prefer it to my current, somewhat hacky, workaround.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
megid2commented, Dec 11, 2019

@z0mbie42 If you add a contact, you do so with an account (e.g. DavX, Google, Exchange etc.), resulting in a “raw” contact. Now suppose you have a raw contact with displayName “Jane Doe” (Google), then add a raw contact “Jane Doe” (Exchange). When reading, you do not lead the two raw contacts, but rather an aggregated/unified contact. So the table looks like this:

displayName | raw id | unified id | account
Jane Doe    | 1      | 1          | google
Jane Doe    | 2      | 1          | exchange

For more detailed examples: http://android-contact-id-vs-raw-contact-id.blogspot.com/

Read more comments on GitHub >

github_iconTop Results From Across the Web

contacts_service | Flutter Package - Pub.dev
A Flutter plugin to retrieve and manage contacts on Android and iOS devices.
Read more >
Not able to add contact using contacts_service in flutter app
But on using ContactsService.addContact(contact); I am getting error. Although contact is saved in the app but not in the phone's contact ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found