getUserContacts function

Future<List<Contact>> getUserContacts()

Retrieves the user's contacts.

Implementation

Future<List<Contact>> getUserContacts() async {
  try {
    final response = await _platform.getUserContacts();
    if (response == null) {
      throw Exception('Unable to get user contacts.');
    }

    final contacts = response['data'] as List<dynamic>;
    return contacts
        .map<Contact>(
          (contact) => Contact.fromJson(Map<String, dynamic>.from(json.decode(json.encode(contact)))),
        )
        .toList();
  } catch (error, stackTrace) {
    Error.throwWithStackTrace(error, stackTrace);
  }
}