flutter_contact 0.4.8 flutter_contact: ^0.4.8 copied to clipboard
A Flutter plugin to retrieve, create and save contacts and contact-related events on Android and iOS devices.
contacts_service #
A Flutter plugin to access and manage the device's native contacts.
Usage #
To use this plugin, add flutter_contact
as a dependency in your pubspec.yaml
file.
For example:
dependencies:
flutter_contact: ^0.4.7+10
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>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.
Example #
// Import package
import 'package:flutter_contact/flutter_contact.dart';
// Get all contacts on device as a stream
Stream<Contact> contacts = await Contacts.streamContacts();
// Get all contacts without thumbnail(faster)
Iterable<Contact> contacts = await Contacts.streamContacts(withThumbnails: false);
// Get contacts matching a string
Stream<Contact> johns = await Contacts.streamContacts(query : "john");
// Add a contact
// The contact must have a firstName / lastName to be successfully added
await Contacts.addContact(newContact);
// Delete a contact
// The contact must have a valid identifier
await Contacts.deleteContact(contact);
// Update a contact
// The contact must have a valid identifier
await Contacts.updateContact(contact);
Credits #
This plugin was originally a fork of the https://pub.dev/packages/contacts_service plugin, but has effectively been mostly rewritten (in part because it was ported to kotlin)