v0.0.12
flutter_native_contact_picker
一个用于从通讯录中选择联系人的 Flutter 插件。
81喜欢 3.7万近 30 天下载160Pub 分数
AndroidiOS
使用此插件,Flutter 应用可以请求用户从其通讯录中选择联系人。与联系人相关的信息将返回给应用。
{"sdk":"flutter"}^2.0.2{"sdk":"flutter"}^6.0.0以下为英文项目原文快照,最新内容请访问 GitHub。
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.
[x] iOS Support
[x] Android Support
// 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);
}
// 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)
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()
}
FlutterFramework requirement)selectPhoneNumber(), returns both the selected number and all available numbersselectPhoneNumber(), returns only the selected phone numberSee 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)),
],
),
),
],
],
),
),
),
);
}
}