我一直被这个问题困扰。如何从flutter中的联系人中选择和获取详细信息?请帮忙。
答案 0 :(得分:0)
withcontacts_service:^ 0.2.5,您可以通过添加查询进行搜索,但是如果您有任何想法,我没有通过电话或电子邮件找到。
https://pub.dev/packages/contacts_service#-readme-tab-
Iterable<Contact> johns = await ContactsService.getContacts(query : "john");
答案 1 :(得分:0)
添加此依赖项
这是当前版本
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(),
),
],
),
),
),
);
}
}
答案 2 :(得分:0)
使用contact_picker: ^0.0.2
获取联系人
在您的pubspec.yaml
文件中添加依赖项
dependencies:
flutter:
sdk: flutter
contact_picker: ^0.0.2
将其导入您要使用的位置并创建一个openContactBook()函数
import 'package:contact_picker/contact_picker.dart';
Future<String> openContactBook() async {
Contact contact = await _contactPicker.selectContact();
if (contact != null) {
var phoneNumber = contact.phoneNumber.number.toString().replaceAll(new RegExp(r"\s+"), "");
return phoneNumber;
}
return "";
}
像这样使用它
onPressed: () {
var contactNumber = openContactBook()
}