Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukasgit/flutter_contacts
A Flutter plugin to retrieve and manage contacts on Android and iOS devices. Maintainer: @lukasgit
https://github.com/lukasgit/flutter_contacts
android flutter flutter-plugin ios
Last synced: 1 day ago
JSON representation
A Flutter plugin to retrieve and manage contacts on Android and iOS devices. Maintainer: @lukasgit
- Host: GitHub
- URL: https://github.com/lukasgit/flutter_contacts
- Owner: lukasgit
- License: mit
- Created: 2019-07-19T14:00:16.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-05T17:55:50.000Z (7 months ago)
- Last Synced: 2025-01-23T05:15:02.729Z (3 days ago)
- Topics: android, flutter, flutter-plugin, ios
- Language: Java
- Homepage: https://pub.dartlang.org/packages/contacts_service
- Size: 1.93 MB
- Stars: 211
- Watchers: 6
- Forks: 262
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome-list - flutter_contacts
README
# contacts_service
[![pub package](https://img.shields.io/pub/v/contacts_service.svg)](https://pub.dartlang.org/packages/contacts_service)
[![Build Status](https://travis-ci.com/lukasgit/flutter_contacts.svg?branch=master)](https://travis-ci.com/lukasgit/flutter_contacts)
[![Coverage Status](https://coveralls.io/repos/github/clovisnicolas/flutter_contacts/badge.svg?branch=master)](https://coveralls.io/github/clovisnicolas/flutter_contacts?branch=master)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](https://flutter.io/platform-plugins/).
For example:
```yaml
dependencies:
contacts_service: ^0.6.3
```
## Permissions
### Android
Add the following permissions to your AndroidManifest.xml:
```xml
```
### iOS
Set the `NSContactsUsageDescription` in your `Info.plist` file
```xml
NSContactsUsageDescription
This app requires contacts access to function properly.
```**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](https://github.com/AppleEducate/flutter_simple_permissions) or [permission_handler](https://pub.dartlang.org/packages/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```dart
// Import package
import 'package:contacts_service/contacts_service.dart';
// Get all contacts on device
List contacts = await ContactsService.getContacts();// Get all contacts without thumbnail (faster)
List contacts = await ContactsService.getContacts(withThumbnails: false);// Android only: Get thumbnail for an avatar afterwards (only necessary if `withThumbnails: false` is used)
Uint8List avatar = await ContactsService.getAvatar(contact);
// Get contacts matching a string
List 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);// 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 User
await ContactsService.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 User
await ContactsService.openExistingContact(contact);```
**Contact Model**
```dart
// Name
String displayName, givenName, middleName, prefix, suffix, familyName;// Company
String company, jobTitle;// Email addresses
List emails = [];// Phone numbers
List phones = [];// Post addresses
List postalAddresses = [];// Contact avatar/thumbnail
Uint8List avatar;```
![Example](doc/example.gif "Example screenshot")
## ContributionsContributions 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](https://github.com/rt2zz/react-native-contacts)