Skip to content
A Flutter plugin to retrieve and manage contacts on Android and iOS devices. Maintainer: @lukasgit
Java Dart Swift Ruby Objective-C
Branch: master
Clone or download
lukasgit Merge pull request #102 from budo385/master
Image streams not closed
Latest commit c9f914d Aug 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
android cursor not closed Jul 19, 2019
doc update changelog, readme, pubspec Jan 30, 2018
example ios get contact by phone number Jun 19, 2019
ios cleanup Jun 19, 2019
lib ios get contact by phone number Jun 19, 2019
test Bug fixes Apr 13, 2019
.gitignore Added test for plugin dart code and code coverage report Aug 26, 2018
.travis.yml Added test for plugin dart code and code coverage report Aug 26, 2018
CHANGELOG.md Update CHANGELOG.md Jun 25, 2019
LICENSE Update LICENSE Jan 30, 2018
README.md
contacts_service.iml begin working on addContact for android Jan 30, 2018
contacts_service_android.iml first commit Jan 29, 2018
pubspec.yaml Update pubspec.yaml Jun 25, 2019

README.md

Flutter Community: contacts_service

contacts_service

pub package Build Status Coverage Status

A Flutter plugin to access and manage the device's contacts.

Usage

To use this plugin, add contacts_service as a dependency in your pubspec.yaml file.
For example:

dependencies:  
    contacts_service: ^0.2.8

Permissions

Android

Add the following permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_CONTACTS" />  
<uses-permission android:name="android.permission.WRITE_CONTACTS" />  

iOS

Set the NSContactsUsageDescription in your Info.plist file

<key>NSContactsUsageDescription</key>  
<string>This app requires contacts access to function properly.</string>  

Note
contacts_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.

Example

// Import package  
import 'package:contacts_service/contacts_service.dart';  
  
// Get all contacts on device
Iterable<Contact> contacts = await ContactsService.getContacts();  

// Get all contacts without thumbnail(faster)
Iterable<Contact> contacts = await ContactsService.getContacts(withThumbnails: false);
  
// Get contacts matching a string
Iterable<Contact> johns = await ContactsService.getContacts(query : "john");

// Add a contact  
// The contact must have a firstName / lastName to be successfully added  
await ContactsService.addContact(newContact);  
  
// Delete a contact
// The contact must have a valid identifier
await ContactsService.deleteContact(contact);  

// Update a contact
// The contact must have a valid identifier
await ContactsService.updateContact(contact);

// Share a contact as a vcf
await shareVCFCard(context, contact: contact),

Contact Model

// Name
String displayName, givenName, middleName, prefix, suffix, familyName;

// Company
String company, jobTitle;

// Email addresses
Iterable<Item> emails = [];

// Phone numbers
Iterable<Item> phones = [];

// Post addresses
Iterable<PostalAddress> postalAddresses = [];

// Contact avatar/thumbnail
Uint8List avatar;

Example

Contributions

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.

Credits

Heavily inspired from rt2zz's react native plugin

You can’t perform that action at this time.