A Flutter plugin to access and manage the device's contacts.
To use this plugin, add contacts_service as a dependency in your pubspec.yaml file.
For example:
dependencies: contacts_service: ^0.6.3Add the following permissions to your AndroidManifest.xml:
<uses-permissionandroid:name="android.permission.READ_CONTACTS" /> <uses-permissionandroid:name="android.permission.WRITE_CONTACTS" /> Set the NSContactsUsageDescription in your Info.plist file
<key>NSContactsUsageDescription</key> <string>This app requires contacts access to function properly.</string> Notecontacts_service 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.
// Import package import'package:contacts_service/contacts_service.dart'; // Get all contacts on deviceList<Contact> contacts =awaitContactsService.getContacts(); // Get all contacts without thumbnail (faster)List<Contact> contacts =awaitContactsService.getContacts(withThumbnails:false);
// Android only: Get thumbnail for an avatar afterwards (only necessary if `withThumbnails: false` is used)Uint8List avatar =awaitContactsService.getAvatar(contact);
// Get contacts matching a stringList<Contact> johns =awaitContactsService.getContacts(query :"john");
// Add a contact // The contact must have a firstName / lastName to be successfully added awaitContactsService.addContact(newContact); // Delete a contact// The contact must have a valid identifierawaitContactsService.deleteContact(contact); // Update a contact// The contact must have a valid identifierawaitContactsService.updateContact(contact);
// Usage of the native device form for creating a Contact// Throws a error if the Form could not be open or the Operation is canceled by the UserawaitContactsService.openContactForm();
// Usage of the native device form for editing a Contact// The contact must have a valid identifier// Throws a error if the Form could not be open or the Operation is canceled by the UserawaitContactsService.openExistingContact(contact);
Contact Model
// NameString displayName, givenName, middleName, prefix, suffix, familyName;
// CompanyString company, jobTitle;
// Email addressesList<Item> emails = [];
// Phone numbersList<Item> phones = [];
// Post addressesList<PostalAddress> postalAddresses = [];
// Contact avatar/thumbnailUint8List avatar;
Contributions are welcome! If you find a bug or want a feature, please fill an issue.
If you want to contribute code please create a pull request under the staging branch.
Heavily inspired from rt2zz's react native plugin
