Reputation: 53
I am actually trying to send SMS to my phone contacts and I did build the app based on this code https://github.com/rodrigoc85/flutter-sms-dispatcher I am trying to import contacts from my phone with the user permission to send SMS.
Please can someone tell me if it's possible and how ?
Many thanks .
Upvotes: 2
Views: 982
Reputation: 7328
You could use the package contacts_service. Here's a code sample taken from its documentation:
import 'package:contacts_service/contacts_service.dart';
// Get all contacts on device
Iterable<Contact> contacts = await ContactsService.getContacts();
The Contact
object has a property phones
which contains all phoneNumbers saved for the contact.
You can grab the phone number like this:
// Get phone numbers for the first contact in list.
Iterable<Item>? phones = contacts.first.phones;
if (phones != null && phones.isNotEmpty) {
String phoneNumber = phones.first.value
}
With Item
class being for contact fields which only have a label and a value, such as emails and phone numbers. And implemented like this:
Item({String? label, String? value})
Upvotes: 0