flutter_contacts 0.0.1
flutter_contacts: ^0.0.1 copied to clipboard
Full-fledged flutter plugin to read, write and observe native contacts.
flutter_contacts #
Fluter plugin to read, create, update, delete and observe native contacts.
For a minimalistic example, take a look at example/. You can write a full-fledged contacts app with it – see example_full/ to see how.
Features #
- List all contacts
- Create new contact
- Update existing contact
- Delete contacts
- Observe contact database changes
- Fetch all details for a given contact, including:
- Photo (low / high resolution)
- Phones
- Emails
- Company / job title
- Postal addresses
- Websites
- Birthday / events
- Instant messaging / social profiles
- Notes
- Labels (such as "main" or "work" for phones)
Screenshots #
Usage #
import 'package:flutter_contacts/flutter_contacts.dart';
/// Get all contacts (IDs and names only)
List<Contact> contacts = await FlutterContacts.getContacts();
/// Get all fields (phones, emails, photo, job, etc) for a given contact
Contact contact = await FlutterContacts.getContact(contacts.first.id);
/// Create contact
Contact newContact = Contact.create()
..name = Name(first: 'John', last: 'Doe')
..phones = [Phone('555-123-4567', label: PhoneLabel.mobile)];
await FlutterContacts.newContact(newContact);
/// Update contact
contact.emails.add(Email('[email protected]'));
await FlutterContacts.updateContact(contact);
/// Delete contact
await FlutterContacts.deleteContact(contact.id);
/// Listen to contacts database changes
FlutterContacts.onChange(() => print('Contact DB changed'));
Installation #
- Add
json_serializable: ^3.5.0(or higher) to thedev_dependenciesinpubspec.yaml. - Add
permission_handler: ^5.0.0+hotfix.3(or higher) to thedependenciesinpubspec.yaml: this is the package that allows you to request for contact permissions. - Add the following
<uses-permissions>tags toAndroidManifest.xml(for Android):
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<application ...>
...
Development notes #
Run build_runner to generate g.dart files #
flutter pub run build_runner build
Format files #
./scripts/format.sh