搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。