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:
- 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, 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-only, override
- id ↔ String
-
The unique identifier of the contact.
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-only, inherited
-
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(
) → Future< Contact> - Updates the contact in the database.
Operators
-
operator ==(
Object o) → bool -
The equality operator. [...]
override