Code Monkey home page Code Monkey logo

easy_contact_picker's Introduction

easy_contact_picker

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

特性

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

用法

添加这一行到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;
    });
  }

easy_contact_picker's People

Contributors

liuweilyy avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.