QuisApp / flutter_contacts

MIT License
84 stars 140 forks source link

BUG : app crash on call FlutterContacts.requestPermission(); #85

Open nastaran-mohammadi opened 1 year ago

nastaran-mohammadi commented 1 year ago

Hi, when I call FlutterContacts.requestPermission(); for the first time app crash and error text is: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {my.redant.leaf/my.redant.leaf.MainActivity}: java.lang.NullPointerException

but after first time, it works fine! tested on both debug and release mode

Shahidbangash commented 1 year ago

Hi, when I call FlutterContacts.requestPermission(); for the first time app crash and error text is: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {my.redant.leaf/my.redant.leaf.MainActivity}: java.lang.NullPointerException

but after first time, it works fine! tested on both debug and release mode

I fixed this issue by adding Permission Handler package and added this code `

  try {

  final PermissionStatus permissionStatus =
  await Permission.contacts.request();

  // isGranted ... Import native

  if (permissionStatus.isGranted) {
    ///  Import Contact Here
  }
} catch (e, stack) {
  log(
    'Error $e',
    stackTrace: stack,
  );
}

`

joachim-quis commented 1 year ago

Thanks for reporting. I will look soon.