Contact class

A contact.

A contact always has a unique id and a displayName.

If the high-resolution photo was fetched and the contact has a photo, photo will be non-null. If the low-resolution photo was fetched and the contact has a photo, thumbnail will be non-null. To access the high-resolution photo if available and the low-resolution thumbnail otherwise, use the getter photoOrThumbnail.

If properties were fetched, fields name, phones, emails, etc will be populated (but might be empty).

If accounts were fetched, accounts will also be populated on Android and are not taken into account for contact equality and hash code. It is exposed for three reasons:

  • most commonly, for debug purposes
  • update needs it to associate properties to the raw ID of the first listed account
  • if provided, insert will use the Account.type and Account.name of the first listed account On iOS, accounts correspond to containers and there can be only one per contact.

If groups are fetched, groups (called labels on Android) will also be populated.

In general no fields or nested fields can be null. For example if a phone is present, contact.phones.first.normalizedNumber cannot be null (but might be empty). Every field defaults to empty string for strings, empty list for lists, 0 for integers, false for booleans, and an appropriate value for label enums. The exceptions are as follows:

These metadata fields indicate what was fetched:

Notable differences between iOS and Android:

Constructors

Contact({String id = '', String displayName = '', Uint8List? thumbnail, Uint8List? photo, bool isStarred = false, Name? name, List<Phone>? phones, List<Email>? emails, List<Address>? addresses, List<Organization>? organizations, List<Website>? websites, List<SocialMedia>? socialMedias, List<Event>? events, List<Note>? notes, List<Account>? accounts, List<Group>? groups})
Contact.fromJson(Map<String, dynamic> json)
factory
Contact.fromVCard(String vCard)
factory

Properties

accounts List<Account>
Raw accounts (Android only).
getter/setter pair
addresses List<Address>
Postal addresses.
getter/setter pair
displayName String
The contact display name.
getter/setter pair
emails List<Email>
Email addresses.
getter/setter pair
events List<Event>
Events / birthdays.
getter/setter pair
groups List<Group>
Groups.
getter/setter pair
hashCode int
The hash code for this object.
no setteroverride
id String
The unique identifier of the contact.
getter/setter pair
isStarred bool
Whether the contact is starred (Android only).
getter/setter pair
isUnified bool
Whether this is a unified contact (and not a raw contact).
getter/setter pair
name Name
Structured name.
getter/setter pair
notes List<Note>
Notes.
getter/setter pair
organizations List<Organization>
Organizations / jobs.
getter/setter pair
phones List<Phone>
Phone numbers.
getter/setter pair
photo Uint8List?
The full-resolution contact picture.
getter/setter pair
photoFetched bool
Whether the high-resolution photo was fetched.
getter/setter pair
photoOrThumbnail Uint8List?
Returns the full-resolution photo if available, the thumbnail otherwise.
no setter
propertiesFetched bool
Whether properties (name, phones, emails, etc).
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
socialMedias List<SocialMedia>
Social media / instant messaging profiles.
getter/setter pair
thumbnail Uint8List?
A low-resolution version of the photo.
getter/setter pair
thumbnailFetched bool
Whether the low-resolution thumbnail was fetched.
getter/setter pair
websites List<Website>
Websites.
getter/setter pair

Methods

deduplicateProperties() → void
Deduplicates properties.
delete() Future<void>
Deletes the contact from the database.
insert() Future<Contact>
Inserts the contact into the database.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson({bool withThumbnail = true, bool withPhoto = true}) Map<String, dynamic>
toString() String
A string representation of this object.
override
toVCard({bool withPhoto = true, String? productId, bool includeDate = false}) String
Exports to vCard format.
update({bool withGroups = false}) Future<Contact>
Updates the contact in the database.

Operators

operator ==(Object o) bool
The equality operator.
override