Skip to content

联系人选择器,可以选择Native通讯录,也可以返回通讯录列表数据。支持iOS、Android

License

Notifications You must be signed in to change notification settings

cnsnet/easy_contact_picker

 
 

Repository files navigation

easy_contact_picker

Flutter 通讯录联系人选择器,同时支持Android和iOS。

特性

在调用获取联系人方法之前需要先获取获取权限,
可以打开Native通讯录选择联系人,也可以返回通讯录列表,自己构建UI。

用法

添加这一行到pubspec.yaml

  easy_contact_picker: ^0.0.2

引用

import 'package:easy_contact_picker/easy_contact_picker.dart';

添加权限

Android

<!-- 读取联系人 -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>

iOS

info.plist中添加读取通讯录权限
Privacy - Contacts Usage Description
Background Modes中 Background fetch 和 Remote notification打对勾

示例1 打开Native通讯录

1.EasyContactPicker中打开Native通讯录方法

Future<List<Contact>> selectContacts() async {
    final List result =
    await _channel.invokeMethod('selectContactList');
    if (result == null) {
      return null;
    }
    List<Contact> contacts = new List();
    result.forEach((f){
      contacts.add(new Contact.fromMap(f));
    });
    return contacts;
  }

2.调用示例

Widget中声明
Contact _contact = new Contact(fullName: "", phoneNumber: "");
final EasyContactPicker _contactPicker = new EasyContactPicker();
Widget中调用
_getContactData() async{
    Contact contact = await _contactPicker.selectContactWithNative();
    setState(() {
      _contact = contact;
    });
  }

示例2 返回通讯录数组

1.EasyContactPicker中返回通讯录数组方法
Future<Contact> selectContactWithNative() async {
    final Map<dynamic, dynamic> result =
    await _channel.invokeMethod('selectContactNative');
    if (result == null) {
      return null;
    }
    return new Contact.fromMap(result);
  }
2.调用示例
Widget中声明
  List<Contact> _list = new List();
  final EasyContactPicker _contactPicker = new EasyContactPicker();
Widget中调用
_getContactData() async{
    List<Contact> list = await _contactPicker.selectContacts();
    setState(() {
      _list = list;
    });
  }

About

联系人选择器,可以选择Native通讯录,也可以返回通讯录列表数据。支持iOS、Android

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 40.3%
  • Objective-C 32.1%
  • Java 19.0%
  • Ruby 8.6%