getPhoneContacts method

  1. @override
Future<void> getPhoneContacts(
  1. ContactSuccessCallback onSuccess,
  2. ContactErrorCallback onError
)
override

Requests permission and returns phone contacts.

Implementation

@override
Future<void> getPhoneContacts(
    ContactSuccessCallback onSuccess, ContactErrorCallback onError) async {
  if (await requestPermission()) {
    try {
      List<fc.Contact> rawContacts = await fc.FastContacts.getAllContacts();
      onSuccess(_toContacts(rawContacts));
      return;
    } catch (e) {
      onError('Failed to fetch contacts');
    }
  } else {
    onError('Permission denied');
  }
}