Home > Back-end >  flutter giving error in displaying contact
flutter giving error in displaying contact

Time:04-18

I was working with contacts in flutter so first I try to print the contacts in flutter and it was printing contact in console in the fine way. but when I try to show the contacts in the screen so it was giving error that "The argument type 'Contact' can't be assigned to the parameter type 'String'" the code using for getting contacts

List<Contact> contacts = await ContactsService.getContacts(withThumbnails: false);

List the contact save in

List<Contact>? Allcontacts;

main body where error it was giving

 body: (Allcontacts == null) ? Center(
    child: CircularProgressIndicator(),
  ):ListView.builder(
    itemCount: Allcontacts?.length,
    itemBuilder: (context, index) {
      return ListTile(
        title: Text("sffd"),
      );
    },
  )

CodePudding user response:

if you mean to display them in the title of the ListTile you should write:

ListTile(
 title: Text(Allcontacts[index].toString()),
);

or if you have a field in Contact Class that have the name of the contact and it is of type String:

ListTile(
 title: Text(Allcontacts[index].name),
);
  • Related