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

GitHub 代码仓SunnyApp/flutter_contact

flutter_contact

一个用于在原生设备上检索、创建、保存和监视联系人的 Flutter 插件

flutter_contact 项目封面
星标
83
复刻
62
最近推送(UTC)
2023年11月24日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

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)

Sunny GitHub avatar
GitHub 作者

Sunny ↗

语言DartKotlinSwiftHTMLRubyObjective-C

此仓库发布的插件

使用的依赖

依赖清单 12 项

  • collection^1.17.2
  • equatable^2.0.5
  • intl^0.18.1
  • logging1.2.0
  • quiver^3.0.1+1
  • uuid^3.0.7
  • dartxx{"path":"/Users/ericm/aesthetika/checkout/ericmartineau/dartxx"}
  • flexidate{"path":"/Users/ericm/aesthetika/checkout/ericmartineau/flexidate"}
  • logging_config{"path":"/Users/ericm/aesthetika/checkout/SunnyApp/logging_config"}
  • flutter{"sdk":"flutter"}
  • pedantic开发依赖^1.11.1
  • flutter_test开发依赖{"sdk":"flutter"}

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗