getAllContacts method

  1. @override
Future<List<Contact>> getAllContacts({
  1. bool withProperties = false,
  2. bool withThumbnail = false,
  3. bool withPhoto = false,
  4. bool sorted = true,
})
override

Gets all contacts from the device.

withProperties - Include phone numbers, emails, etc. withThumbnail - Include thumbnail images. withPhoto - Include full-size photos. sorted - Sort contacts alphabetically.

Implementation

@override
Future<List<Contact>> getAllContacts({
  bool withProperties = false,
  bool withThumbnail = false,
  bool withPhoto = false,
  bool sorted = true,
}) async {
  try {
    final result = await methodChannel.invokeMethod<List<dynamic>>(
      'getAllContacts',
      {
        'withProperties': withProperties,
        'withThumbnail': withThumbnail,
        'withPhoto': withPhoto,
        'sorted': sorted,
      },
    );

    return result
            ?.map<Contact>(
              (dynamic item) => Contact.fromJson(_safeMapCast(item)),
            )
            .toList() ??
        <Contact>[];
  } on PlatformException catch (e) {
    throw Exception('Failed to get contacts: ${e.message}');
  }
}