搜索插件、代码仓与 APP 分类

插件详情v0.6.3

contacts_service

一个用于在 Android 和 iOS 设备上检索和管理联系人的 Flutter 插件。

AndroidiOS
近 30 天下载
2880
喜欢数
599
Pub 分数
140

安装插件

flutter pub add contacts_service

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

contacts_service 包是一个 Flutter 插件,可让开发者在 Android 和 iOS 平台上访问和管理设备联系人。它提供了一致的 API 来获取联系人列表、读取联系人详细信息(如姓名、电话号码和电子邮件),并支持过滤和搜索等基本操作。该包专为跨平台兼容性设计,无需编写特定于平台的代码即可简化与原生联系人系统的集成。该包非常适合需要联系人查找或导入功能的应用程序。

适合场景

  • 联系人列表检索
  • 联系人搜索和筛选
  • 将联系人导入应用
  • 同步联系人与应用数据
  • 在UI中显示联系人详细信息

主要特点

  • 跨平台支持(Android 和 iOS)
  • 联系人访问的简单 API
  • 支持联系人字段,如姓名、电话、电子邮件
  • 搜索和筛选功能
  • 无需原生代码

适合对象

  • 需要联系人访问权限的应用
  • 用户资料导入工具
  • 通讯应用
  • CRM 集成
  • 联系人选择器小部件

使用建议

  • Android 和 iOS 需要运行时权限
  • 仅限基本联系人操作
  • 需要隐私合规
  • 可能需要用户同意才能访问
  • 性能取决于设备联系人数据库的大小

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

contacts_service

pub package Build Status Coverage Status

A Flutter plugin to access and manage the device's contacts.

Usage

To use this plugin, add contacts_service as a dependency in your pubspec.yaml file.
For example:

dependencies:  
    contacts_service: ^0.6.3

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

<key>NSContactsUsageDescription</key>  
<string>This app requires contacts access to function properly.</string>  

Note
contacts_service 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:contacts_service/contacts_service.dart';  
  
// Get all contacts on device
List<Contact> contacts = await ContactsService.getContacts();  

// Get all contacts without thumbnail (faster)
List<Contact> contacts = await ContactsService.getContacts(withThumbnails: false);

// Android only: Get thumbnail for an avatar afterwards (only necessary if `withThumbnails: false` is used)
Uint8List avatar = await ContactsService.getAvatar(contact);
  
// Get contacts matching a string
List<Contact> johns = await ContactsService.getContacts(query : "john");

// Add a contact  
// The contact must have a firstName / lastName to be successfully added  
await ContactsService.addContact(newContact);  
  
// Delete a contact
// The contact must have a valid identifier
await ContactsService.deleteContact(contact);  

// Update a contact
// The contact must have a valid identifier
await ContactsService.updateContact(contact);

// Usage of the native device form for creating a Contact
// Throws a error if the Form could not be open or the Operation is canceled by the User
await ContactsService.openContactForm();

// Usage of the native device form for editing a Contact
// The contact must have a valid identifier
// Throws a error if the Form could not be open or the Operation is canceled by the User
await ContactsService.openExistingContact(contact);

Contact Model

// Name
String displayName, givenName, middleName, prefix, suffix, familyName;

// Company
String company, jobTitle;

// Email addresses
List<Item> emails = [];

// Phone numbers
List<Item> phones = [];

// Post addresses
List<PostalAddress> postalAddresses = [];

// Contact avatar/thumbnail
Uint8List avatar;

Example

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 under the staging branch.

Credits

Heavily inspired from rt2zz's react native plugin

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目