flutter_contact 0.4.14

contacts_service #

pub package Coverage Status

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:

    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

<string>Your description of why you are requesting permissions.</string>  

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.

Memory Efficiency #

This plugin tries to be memory and cpu friendly. It avoid loading your entire address book into memory, but rather provides a couple ways to access all contacts.

Stream #

import 'package:flutter_contact/flutter_contact.dart';  

// By default, this will loop through all contacts using a page size of 20.
await Contacts.streamContacts().forEach((contact) {

// You can manually adjust the buffer size
Stream<Contact> contacts = await Contacts.streamContacts(bufferSize: 50);

Paging List #

The second option is a paging list, which also uses an underlying page buffer, but doesn't have any subscriptions to manage, and has some other nice features, like a total count

import 'package:flutter_contact/flutter_contact.dart';

final contacts = Contacts.listContacts();
final total = await contacts.length;

// This will fetch the page this contact belongs to, and return the contact
final contact = await contacts.get(total - 1);

while(await contacts.moveNext()) {
    final contact = await contacts.current;

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);

/// Lazily fetch avatar data without caching it in the contact instance.
final contact = Contacts.getContact(contactId);
final Uint8List avatarData = await contact.getOrFetchAvatar();

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)

0.4.14 #

  • Fixing bug with paging iterable that attempted to publish after the stream was closed

0.4.13 #

  • Fixing contact events on ios

0.4.10 #

  • Improving docs

0.4.9 #

  • Getting Android up to speed

0.4.8 #

  • Adding documentation
  • Working on CI setup

0.4.7+10 #

  • Adding sort order

0.4.7+9 #

  • Fixing issue with fetching full-res images

0.4.7+8 #

  • Improved performance of count
  • Beefed up example screen to handle search and other features.
  • Known issue: this build doesn't work for Android

0.4.7+7 #

  • Move all ios operation to background as .userInitiated
  • Provide convenience getter for fetching contact avatar.

0.4.7+6 #

  • Fixing ios paging logic

0.4.7+5 #

  • Added streaming methods for improved performance

0.4.7+4 #

  • Fixing issue with copying identifier
  • Also improved error handling

0.4.7+3 #

  • Added removeDuplicates function to contact
  • Fixed some issues with dates (specifically birthday on IOS)

0.4.6 #

  • Fixed exports

0.4.5 #

  • Changed how dates are handled - more closely aligning to DateComponents in ios - will use a kotlin class for Android eventually

0.4.4 #

  • Initial checkin


flutter_contact_example #

Demonstrates how to use the flutter_contact plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_contact: ^0.4.14

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_contact/contact.dart';
import 'package:flutter_contact/contact_events.dart';
import 'package:flutter_contact/contacts.dart';
import 'package:flutter_contact/date_components.dart';
import 'package:flutter_contact/generated/i18n.dart';
import 'package:flutter_contact/group.dart';
import 'package:flutter_contact/logging.dart';
import 'package:flutter_contact/paging_iterable.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 12, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
collection ^1.14.11 1.14.11 1.14.12
equatable ^1.0.1 1.1.0
flutter 0.0.0
intl ^0.16.0 0.16.1
logging ^0.11.3+2 0.11.4
pedantic ^1.8.0+1 1.9.0
quiver ^2.0.5 2.1.2+1
uuid ^2.0.4 2.0.4
Transitive dependencies
charcode 1.1.3
convert 2.1.1
crypto 2.1.4
matcher 0.12.6
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
stack_trace 1.9.3
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies