raw_contacts 0.0.4 raw_contacts: ^0.0.4 copied to clipboard
Manage Contact lists in flutter
raw_contacts #
A Flutter plugin to access and manage the device's contacts. (Android Only for now)
Usage #
To use this plugin, add raw_contacts
as a dependency in your pubspec.yaml
file.
For example:
dependencies:
raw_contacts: ^0.0.1
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" />
Note
raw_contacts
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:raw_contacts/raw_contacts.dart';
String _accountType="com.test_app";
// Get all contact list for the account type
Iterable<Contact> contacts = await RawContacts.getContacts(filter: _accountType);
// Get all contacts without thumbnail(faster)
Iterable<Contact> contacts = await RawContacts.getContacts(getImages: false,filter: _accountType);
// Add a contact
// The contact must have at least DisplayName and Email
await RawContacts.addContact(newContact);
// Delete a contact
// The contact must have a valid identifier
await RawContacts.deleteContact(contact);
Contact Model
// Name
String displayName, givenName, middleName, prefix, suffix, familyName;
// Company
String company, jobTitle;
// Email addresses
Iterable<KeyValuePair> emails = [];
// Phone numbers
Iterable<KeyValuePair> phones = [];
// Post addresses
Iterable<PostalAddress> postalAddresses = [];
// Contact avatar/thumbnail
Uint8List avatar;
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.