fcontacts 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

fcontacts #

pub package

A Flutter plugin for accessing to all available data from your phone contacts. Supports iOS and Android.

Getting Started #

In Android, you need to add the READ_CONTACTS permission in your AndroidManifest.xml.

<uses-permission android:name="android.permission.READ_CONTACTS" />

In iOS, you need to add the key NSContactsUsageDescription in your Info.plist file.

<key>NSContactsUsageDescription</key>
<string>We need access to your contacts for this demo</string>

Usage #

Import package #

To use this plugin you must add fcontacts as a dependency in your pubspec.yaml file.

dependencies:
    fcontacts: ^1.1.0

Example #

import 'package:fcontacts/fcontacts.dart';

Listing all the contacts in your device:

List<FContact> allContacts = await FContacts.all();

Listing contacts filtered by a query string:

List<FContact> filteredContacts = await FContacts.list( query: "abc" );
// The fields used to filter are:
//  - identifier
//  - displayName
//  - nickname
//  - jobTitle
//  - departmentName
//  - organizationName
//  - note
//  - postalAddresses (street, city, subLocality, subAdministrativeArea, postalCode, state, country)
//  - emails
//  - urls
//  - phoneNumbers
//  - socialProfiles (service, userIdentifier, username, url)
//  - contactRelations
//  - instantMessageAddresses (service, username)

Models #

FContact #

class FContact {
    String identifier;
    String displayName;
    String contactType;
    String namePrefix;
    String givenName;
    String middleName;
    String familyName;
    String previousFamilyName;              // Only in iOS
    String nameSuffix;
    String nickname;
    String phoneticGivenName;               // Only in iOS
    String phoneticMiddleName;              // Only in iOS
    String phoneticFamilyName;              // Only in iOS
    String jobTitle;
    String departmentName;                  // Only in iOS
    String organizationName;
    String phoneticOrganizationName;        // Only in iOS
    String note;                            // Only in Android
    Uint8List image;
    Uint8List thumbnail;

    List<FContactDateLabeled> dates;
    List<FContactPostalAddressLabeled> postalAddresses;
    List<FContactValueLabeled> emails;
    List<FContactValueLabeled> urls;
    List<FContactValueLabeled> phoneNumbers;
    List<FContactSocialProfileLabeled> socialProfiles;                      // Only in iOS
    List<FContactValueLabeled> contactRelations;
    List<FContactInstantMessageAddressLabeled> instantMessageAddresses;

}

FContactValueLabeled #

class FContactValueLabeled {
    String label;
    String value;
}

FContactDateLabeled #

class FContactDateLabeled {
    String label;
    int day;
    int month;
    int year;
}

FContactPostalAddressLabeled #

class FContactPostalAddressLabeled {
    String label;
    String street;
    String city;
    String subLocality;
    String subAdministrativeArea;
    String postalCode;
    String state;
    String country;
    String isoCountryCode;
    String formatted;
}

FContactSocialProfileLabeled #

class FContactSocialProfileLabeled {
    String label;
    String service;
    String userIdentifier;
    String username;
    String url;
}

FContactInstantMessageAddressLabeled #

class FContactInstantMessageAddressLabeled {
    String label;
    String service;
    String username;
}

Limitations #

  • The Notes field in iOS is not available for now.

Credits #

This plugin has been created and developed by Daniel Martínez.

Any suggestions and contributions are welcomed. Thanks for using this plugin!

1.1.0 (11/10/2019) #

  • #1: Bug fixed
  • Birthday is now included as a FContactDateLabeled inside the 'dates' list in the Contact model

1.0.0 (09/10/2019) #

  • Added API documentation

0.0.3 (09/10/2019) #

  • Fixed example README

0.0.2 (09/10/2019) #

  • Added a query method to filter contacts

0.0.1 (09/10/2019) #

  • Published plugin
  • Added a method to list all contacts

example/README.md

fcontacts_example #

This is a code example on how to use this plugin. You can check the files used in our repository.

main.dart #

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:fcontacts/fcontacts.dart';

void main() => runApp(FContactsApp());

class FContactsApp extends StatefulWidget {
  @override
  _FContactsAppState createState() => _FContactsAppState();
}

class _FContactsAppState extends State<FContactsApp> {

  TextEditingController searchController = TextEditingController();

  List<FContact> all = List();
  List<FContact> filtered = List();

  @override
  void initState() {
    super.initState();
    _loadContacts().then( (_list) {
      setState(() {
        this.all = _list;
        this.filtered = _list;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('My Contacts (${this.filtered.length})'),
        ),
        body: Container(
          child: Column(
              children: [
                Padding(
                    padding: EdgeInsets.all( 8.0 ),
                    child: TextField(
                      onChanged: (text) {
                        filter(text);
                      },
                      controller: searchController,
                      decoration: InputDecoration(
                        hintText: "Type to search...",
                        prefixIcon: Icon(Icons.search)
                      ),
                    )
                ),
                Expanded(
                    child: ListView.separated(
                        shrinkWrap: true,
                        itemCount: this.filtered.length,
                        itemBuilder: (BuildContext context, int index) {
                          final FContact item = this.filtered[index];
                          return ListTile(
                            title: Text( item.displayName ),
                            subtitle: Text( item.identifier )
                          );
                        },
                        separatorBuilder: (context, index) {
                          return Divider();
                        }
                    )
                )
              ]
          )
        ),
      ),
    );
  }

  Future<List<FContact>> _loadContacts() async {
    return await FContacts.all();
  }

  void filter( String query ) async {
    if (query.isNotEmpty) {
      List<FContact> _filtered = await FContacts.list( query: query );
      setState(() {
        this.filtered = _filtered;
      });
    } else {
      setState(() {
        this.filtered = this.all;
      });
    }
  }

}

Credits #

This plugin has been created and developed by Daniel Martínez.

Any suggestions and contributions are welcomed. Thanks for using this plugin!

Use this package as a library

1. Depend on it

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


dependencies:
  fcontacts: ^1.1.0

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:fcontacts/fcontacts.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
34
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Dec 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

128 out of 128 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/fcontacts.dart.

Run flutter format to format lib/fcontacts.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test