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:
- thumbnail and photo can be null
- Event.year can be null for dates with no year
- Event.month defaults to 1
- Event.day defaults to 1
These metadata fields indicate what was fetched:
- thumbnailFetched if low-resolution thumbnail was fetched
- photoFetched if high-resolution photo was fetched
- propertiesFetched if name, phones, emails, etc were fetched
Notable differences between iOS and Android:
- iOS only supports one note
- on iOS13+ the app needs to be explicitly approved by Apple (see
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_contacts_notes);
if your app is entitled, you can use
FlutterContacts.config.includeNotesOnIos13AndAbove = true
to include them in the properties when fetching/inserting/updating contacts - iOS supports only one Event of type EventLabel.birthday
- iOS doesn't support Phone.isPrimary and Email.isPrimary
- labels vary widely between the two platforms, meaning that, for example, if you save a contact with PhoneLabel.iPhone on Android, under the hood it will get saved as PhoneLabel.custom and Phone.customLabel = 'iPhone'
- available fields vary widely between the two platforms, for example Address.isoCountry is not available on Android and Address.neighborhood is not available on iOS, so if you save a contact with data for Address.neighborhood on iOS, that data will be lost
- accounts represent raw accounts on Android and containers on iOS
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
-
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