Closed Calamari closed 5 years ago
After more thinking about it, I got it myself. For future reference, this happens when you don't have the permissions to read the contacts. What I was missing was the simple_permissions plugin.
So a basic and valid initialState
method could look like this:
@override
void initState() {
SimplePermissions
.requestPermission(Permission.ReadContacts)
.then((status) {
if (status != PermissionStatus.authorized) {
debugPrint("no read rights. Aborting mission!");
return;
}
debugPrint("start loading contacts");
ContactsService.getContacts().then((foundContacts) {
debugPrint("done loading contacts" + foundContacts.length.toString());
final list = foundContacts.toList();
list.sort((a, b) => a.givenName.compareTo(b.givenName));
setState(() {
contacts = list;
});
}).catchError((error) {
debugPrint(error.toString());
});
});
super.initState();
}
Sorry for eagerly posting issues. But maybe this helps someone else along the line.
And boys: Read the Readmes more carefully than me, so you don't get this problems. ;)
Btw: Thanks for this plugin!
Hey guys.
I am in a bit of a pickle right now, since I am trying building an app that needs to reads the mobiles contacts but somehow it just fails miserably at this. And I am missing clues how to debug this – since the error message is less than helpful.
Here is the widget I am trying to run:
And here is what the debug console outputs:
Maybe I am doing something really stupid – which totally might happen since I am fairly new to flutter and stuff – but I think it should work. So if anyone knows what is going on, or how to find the crux, I would be really indebted to you.
Not quite sure what you could need to help, so here is the
flutter doctor
output:I am trying this in the simulator with a
Nexus_5X_api_28_64
device.Any ideas?