A Flutter plugin for accessing to all available data from your phone contacts. Supports iOS and Android.
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>
To use this plugin you must add fcontacts
as a dependency in your pubspec.yaml
file.
dependencies:
fcontacts: ^1.1.0
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)
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;
}
class FContactValueLabeled {
String label;
String value;
}
class FContactDateLabeled {
String label;
int day;
int month;
int year;
}
class FContactPostalAddressLabeled {
String label;
String street;
String city;
String subLocality;
String subAdministrativeArea;
String postalCode;
String state;
String country;
String isoCountryCode;
String formatted;
}
class FContactSocialProfileLabeled {
String label;
String service;
String userIdentifier;
String username;
String url;
}
class FContactInstantMessageAddressLabeled {
String label;
String service;
String username;
}
- The Notes field in iOS is not available for now.
This plugin has been created and developed by Daniel MartĂnez.
Any suggestions and contributions are welcomed. Thanks for using this plugin!