Contact class Null safety

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

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 non-existent 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