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

插件详情v0.9.1+8

flutter_contact

一个 Flutter 插件,用于在 Android 和 iOS 设备上检索、创建和保存联系人及联系人相关事件。

AndroidiOS
近 30 天下载
75
喜欢数
60
Pub 分数
120

安装插件

flutter pub add flutter_contact

插件介绍

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

flutter_contact 是一个 Flutter 插件,使开发者能够在 Android 和 iOS 设备上访问、创建和管理联系人及其相关事件。它提供了一个统一的接口来与原生联系人系统交互,允许用户检索联系人详细信息、添加新联系人以及处理联系人更改。该插件支持读取联系人列表、添加或更新联系人信息以及管理联系人照片等基本操作。它设计为跨平台无缝工作,配置简单。

适合场景

  • 访问设备联系人列表
  • 通过编程方式创建新联系人
  • 更新现有联系人信息
  • 处理联系人照片管理
  • 同步联系人与应用数据
  • 集成联系人选择器功能

主要特点

  • 跨平台支持(Android 和 iOS)
  • 检索和管理联系人详细信息
  • 添加、更新和删除联系人
  • 联系人照片支持
  • 基于事件的联系人变更检测
  • 用于常见联系人操作的简单 API

适合对象

  • 联系人管理应用
  • CRM 应用程序
  • 用户资料同步
  • 带有联系人集成的通信应用
  • 需要联系人导入/导出的应用

使用建议

  • 两个平台都需要适当的权限
  • 仅限基本联系人操作
  • 可能需要对复杂的联系人字段进行额外处理
  • 平台特定的行为差异
  • 联系人访问可能带来的隐私问题
  • 需要对权限拒绝情况进行适当的错误处理

原始 README

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

flutter_contact

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:

dependencies:  
    flutter_contact: ^0.6.1

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>Your description of why you are requesting permissions.</string>  

Note
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.

Unified vs Single contacts

There are two main entry points into the application: SingleContacts and UnifiedContacts. These share the same API and most of the underlying code, however:

  • SingleContacts will interact with the unlinked raw contacts on each platform
  • UnifiedContacts will interact with linked/aggregated contacts on each platform.

Memory Efficiency

This plugin tries to be memory and cpu friendly. It avoid loading your entire address book into memory, but rather provides some ways to iterate over contacts in a more memory friendly way:

Stream
import 'package:flutter_contact/contact.dart';  

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

// 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/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/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/flutter_contact plugin, but has effectively been mostly rewritten (in part because it was ported to kotlin)

所属分类

依赖

依赖清单 9 项

源码仓库

使用此插件的项目

暂无相关数据。