Closed MatrixDev closed 2 years ago
The app developer should check if permissions were granted before using any of the FlutterContacts methods such as FlutterContacts.getContacts()
. You can do so directly with:
if (await FlutterContacts.requestPermission()) {
final contacts = FlutterContacts.getContacts();
...
}
which I believe is your suggestion #2.
If permissions were already granted, it won't request them again.
As I stated above - it is not always a good practice to request
permission and I couldn't find how to actually check
for permissions in this plugin.
it is not always a good practice to request permission
Sorry but what is the alternative? You HAVE TO request permission to be able to access contacts. This is enforced both by Android and iOS.
I couldn't find how to actually check for permissions in this plugin.
As stated above, if permissions were already granted, await FlutterContacts.requestPermission()
will silently return true and won't re-request permissions. I believe this is what you want.
check
doesn't mean request
. I'm asking about checking permissions without actually requesting them. I understand how requestPermission
works BTW.
What I'm asking is an alternative to https://developer.android.com/reference/android/content/Context#checkSelfPermission(java.lang.String) .
Ah, got it. Currently this is not possible with flutter_contacts
, but you can have more fine-grained control over permissions with packages such as permission_handler
(https://pub.dev/packages/permission_handler).
FlutterContacts.getContacts()
crashes when permissions are not granted.It is not always a good practice to ask for permissions in advance (for ex. if we need to sync during app start) and storing somewhere a flag whether permissions were granted before is a not a good idea either as they can be revoked.
Suggestion (any or both):
FlutterContacts.isPermissionGranted()