如何从flutter中的联系人中选择单个联系人 [英] How to select a single contact from contacts in flutter

查看:42
本文介绍了如何从flutter中的联系人中选择单个联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直被这个问题困扰.如何从颤动的联系人中选择和获取详细信息?请帮忙.

I have been stuck on this problem. How to select and fetch details from a contact in flutter? Please ​help.

推荐答案

添加这个依赖

这是目前的版本

contact_picker: ^0.0.2

contact_picker: ^0.0.2

import 'package:flutter/material.dart';
import 'package:contact_picker/contact_picker.dart';

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

class MyApp extends StatefulWidget {
 @override
_MyAppState createState() => new _MyAppState();
}

 class _MyAppState extends State<MyApp> {
  final ContactPicker _contactPicker = new ContactPicker();
  Contact _contact;

  @override
  Widget build(BuildContext context) {
   return new MaterialApp(
   home: new Scaffold(
    appBar: new AppBar(
       title: new Text('Plugin example app'),
     ),
      body: new Center(
      child: new Column(
        mainAxisSize: MainAxisSize.min,
         children: <Widget>[
          new MaterialButton(
            color: Colors.blue,
            child: new Text("CLICK ME"),
            onPressed: () async {
              Contact contact = await _contactPicker.selectContact();
              setState(() {
                _contact = contact;
              });
            },
          ),
          new Text(
            _contact == null ? 'No contact selected.' : _contact.toString(),
          ),
        ],
      ),
    ),
  ),
);
 }
}

这篇关于如何从flutter中的联系人中选择单个联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆