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

原始碼儲存庫

使用此套件的專案