Package selection guidance compiled from public package information, community data, and project usage.
flutter_contact is a Flutter plugin that enables developers to access, create, and manage contacts and contact-related events on both Android and iOS devices. It provides a unified interface for interacting with the native contact systems, allowing users to retrieve contact details, add new contacts, and handle contact changes. The plugin supports essential operations like reading contact lists, adding or updating contact information, and managing contact photos. It's designed to work seamlessly across platforms with minimal configuration.
Use cases
Accessing device contact list
Creating new contacts programmatically
Updating existing contact details
Handling contact photo management
Synchronizing contacts with app data
Integrating contact picker functionality
Key features
Cross-platform support (Android & iOS)
Retrieve and manage contact details
Add, update, and delete contacts
Support for contact photos
Event-driven contact change detection
Simple API for common contact operations
Suitable for
Contact management apps
CRM applications
User profile synchronization
Communication apps with contact integration
Apps requiring contact import/export
Considerations
Requires appropriate permissions on both platforms
Limited to basic contact operations
May require additional handling for complex contact fields
Platform-specific behavior differences
Potential privacy concerns with contact access
Needs proper error handling for permission denials
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
flutter_contact
A Flutter plugin to access and manage the device's native contacts.
Set the NSContactsUsageDescription in your Info.plist file
<key>NSContactsUsageDescription</key><string>Your description of why you are requesting permissions.</string>
Note flutter_contact does not handle the process of asking and checking for permissions. To check and request user permission to access contacts, try using the following plugins: flutter_simple_permissions or permission_handler.
If you do not request user permission or have it granted, the application will fail. For testing purposes, you can manually set the permissions for your test app in Settings for your app on the device that you are using. For Android, go to "Settings" - "Apps" - select your test app - "Permissions" - then turn "on" the slider for contacts.
Unified vs Single contacts
There are two main entry points into the application: SingleContacts and UnifiedContacts. These share
the same API and most of the underlying code, however:
SingleContacts will interact with the unlinked raw contacts on each platform
UnifiedContacts will interact with linked/aggregated contacts on each platform.
Memory Efficiency
This plugin tries to be memory and cpu friendly. It avoid loading your entire address book into memory,
but rather provides some ways to iterate over contacts in a more memory friendly way:
Stream
import'package:flutter_contact/contact.dart';
// By default, this will loop through all contacts using a page size of 20.awaitContacts.streamContacts().forEach((contact) {
print("${contact.displayName}");
});
// You can manually adjust the buffer sizeStream<Contact> contacts = awaitContacts.streamContacts(bufferSize: 50);
Paging List
The second option is a paging list, which also uses an underlying page buffer,
but doesn't have any subscriptions to manage, and has some other nice features, like
a total count
import'package:flutter_contact/contact.dart';
final contacts = Contacts.listContacts();
final total = await contacts.length;
// This will fetch the page this contact belongs to, and return the contactfinal contact = await contacts.get(total - 1);
while(await contacts.moveNext()) {
final contact = await contacts.current;
}
Example
// Import package import'package:flutter_contact/contact.dart';
// Get all contacts on device as a streamStream<Contact> contacts = awaitContacts.streamContacts();
// Get all contacts without thumbnail(faster)Iterable<Contact> contacts = awaitContacts.streamContacts(withThumbnails: false);
// Get contacts matching a stringStream<Contact> johns = awaitContacts.streamContacts(query : "john");
// Add a contact // The contact must have a firstName / lastName to be successfully added awaitContacts.addContact(newContact);
// Delete a contact// The contact must have a valid identifierawaitContacts.deleteContact(contact);
// Update a contact// The contact must have a valid identifierawaitContacts.updateContact(contact);
/// Lazily fetch avatar data without caching it in the contact instance.final contact = Contacts.getContact(contactId);
finalUint8List avatarData = await contact.getOrFetchAvatar();
Credits
This plugin was originally a fork of the
https://pub.dev/packages/flutter_contact plugin, but has effectively been mostly rewritten (in
part because it was ported to kotlin)