advanced_native_contact_picker 0.0.3
advanced_native_contact_picker: ^0.0.3 copied to clipboard
A Flutter plugin for picking contacts using native system UIs on Android and iOS without requiring explicit permissions.
import 'package:flutter/material.dart';
import 'package:advanced_native_contact_picker/advanced_native_contact_picker.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final TextEditingController _numberController = TextEditingController();
String? _contactName;
@override
void dispose() {
_numberController.dispose();
super.dispose();
}
Future<void> _pickContact() async {
final contacts = await NativeContactPicker.pickContact();
if (contacts.isNotEmpty) {
final contact = contacts.first;
setState(() {
_contactName = contact.name;
if (contact.phones.isNotEmpty) {
_numberController.text = contact.phones.first.value;
} else {
_numberController.text = '';
}
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Contact Picker Example')),
body: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: _numberController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: 'Phone Number',
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: const Icon(Icons.contacts),
onPressed: _pickContact,
tooltip: 'Pick a contact',
),
),
),
const SizedBox(height: 16),
if (_contactName != null && _contactName!.isNotEmpty)
Text(
'Selected Name: $_contactName',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
);
}
}