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

原始碼儲存庫

使用此套件的專案