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

插件详情v0.0.13

flutter_native_contact_picker

一个用于从通讯录中选择联系人的 Flutter 插件。

AndroidiOS
近 30 天下载
5.8万
喜欢数
82
Pub 分数
160

安装插件

flutter pub add flutter_native_contact_picker

插件介绍

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

一个 Flutter 插件,允许用户直接从 Android 和 iOS 设备的原生通讯录中选择联系人。它提供无缝的、平台原生的联系人选择界面,确保跨平台的一致用户体验。该插件与设备内置的联系人系统集成,可访问联系人信息,如姓名、电话号码和电子邮件。它设计简洁可靠,非常适合需要联系人集成但无需自行构建自定义联系人选择器的应用。

适合场景

  • 在消息应用中集成联系人选择
  • 通过联系人导入启用用户资料创建
  • 促进快速联系人共享
  • 支持通过联系人查找进行预约安排
  • 使用联系人检索构建CRM工具

主要特点

  • Android 和 iOS 的原生联系人选择器 UI
  • 访问联系人详细信息,如姓名和电话号码
  • 联系人选择的简单 API
  • 跨平台兼容性
  • 使用平台权限进行安全数据处理

适合对象

  • 开发通信应用的开发者
  • 需要联系人导入功能的应用
  • 用于潜在客户生成或人脉拓展的工具
  • 需要联系人输入的移动表单
  • 带有用户引导流程的应用程序

使用建议

  • 在 Android 和 iOS 上需要运行时权限
  • 可能不支持所有联系人字段(例如照片)
  • 依赖于设备的原生联系人数据库
  • 选择器 UI 的自定义功能有限
  • 需要对权限拒绝情况进行适当的错误处理

原始 README

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

flutter_native_contact_picker

With this plugin a Flutter app can ask its user to select a contact or contacts from their address book, with the option to select specific phone numbers. The information associated with the contacts is returned to the app.

This plugin uses the operating system's native UI for selecting contacts and does not require any special permissions from the user, even on Android.

Features

  • [x] iOS Support

    • Select single contact
    • Select multiple contacts
    • Select specific phone number from a contact
    • Returns all phone numbers for selected contacts
  • [x] Android Support

    • Select single contact
    • Select specific phone number from a contact
    • No READ_CONTACTS permission required

Usage

Basic Contact Selection
// Create an instance of the picker
final FlutterNativeContactPicker _contactPicker = FlutterNativeContactPicker();

// Select a single contact
Contact? contact = await _contactPicker.selectContact();
print(contact?.fullName);
print(contact?.phoneNumbers);

// Select multiple contacts (iOS only)
List<Contact>? contacts = await _contactPicker.selectContacts();
for (var contact in contacts ?? []) {
  print(contact.fullName);
  print(contact.phoneNumbers);
}
Phone Number Selection
// Select a specific phone number from a contact
Contact? contact = await _contactPicker.selectPhoneNumber();
print(contact?.fullName);
print(contact?.selectedPhoneNumber); // The specifically selected number
print(contact?.phoneNumbers); // All available numbers (iOS only)

Contact Model

The Contact class provides the following properties:

class Contact {
  final String? fullName;           // Contact's full name
  final List<String>? phoneNumbers; // All phone numbers (iOS: all numbers, Android: selected number only)
  final String? selectedPhoneNumber; // The specifically selected phone number when using selectPhoneNumber()
}

Platform Differences

iOS
  • Minimum iOS 13.0 (Swift Package Manager integration and Flutter FlutterFramework requirement)
  • Supports selecting multiple contacts
  • Returns all phone numbers associated with a contact
  • When using selectPhoneNumber(), returns both the selected number and all available numbers
  • Uses native CNContactPickerViewController
Android
  • Single contact selection only
  • When using selectPhoneNumber(), returns only the selected phone number
  • No READ_CONTACTS permission required
  • Uses native contact picker intent

Example

See the example directory for a complete sample app demonstrating all features.

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final FlutterNativeContactPicker _contactPicker = FlutterNativeContactPicker();
  List<Contact>? _contacts;
  String? _selectedPhoneNumber;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Contact Picker Example App'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              MaterialButton(
                color: Colors.blue,
                textColor: Colors.white,
                child: const Text("Select Contact"),
                onPressed: () async {
                  Contact? contact = await _contactPicker.selectContact();
                  setState(() {
                    _contacts = contact == null ? null : [contact];
                    _selectedPhoneNumber = null;
                  });
                },
              ),
              MaterialButton(
                color: Colors.green,
                textColor: Colors.white,
                child: const Text("Select Phone Number"),
                onPressed: () async {
                  Contact? contact = await _contactPicker.selectPhoneNumber();
                  setState(() {
                    _contacts = contact == null ? null : [contact];
                    _selectedPhoneNumber = contact?.selectedPhoneNumber;
                  });
                },
              ),
              if (_contacts != null) ...[
                ..._contacts!.map(
                  (contact) => Column(
                    children: [
                      Text(contact.fullName ?? 'No name'),
                      if (_selectedPhoneNumber != null)
                        Text('Selected: $_selectedPhoneNumber'),
                      ...?contact.phoneNumbers?.map((number) => Text(number)),
                    ],
                  ),
                ),
              ],
            ],
          ),
        ),
      ),
    );
  }
}

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.0.2

源码仓库

使用此插件的项目