Instance of in Flutter

I’m using contacts_service: ^0.6.0 package, and I want to print the phone numbers from my phone book but it is printing Instance of < Contact > instead of actual phone number.

This is my phones screenshot

This is my output in debug panal.

I/flutter ( 8457): [Instance of 'Contact', Instance of 'Contact'].

This is my code:

`

_getContacts() async {
    List<Contact> _contacts =
    (await ContactsService.getContacts(withThumbnails: false)).toList();
    setState(() {
      contacts.addAll(_contacts);
      print(contacts);
    });
  }`

Answer

Because you are printing the Instance itself, not the data inside them. So to print the data inside the Contact Instance you need to extract the data from it. For example:

_getContacts() async {
 List<Contact> _contacts =
 (await ContactsService.getContacts(withThumbnails: false)).toList();
 setState(() {
   contacts.addAll(_contacts);
   for(var i=0; i<contacts.length; i++){
     print(contacts[i].displayName);
   }
 });
}