askPermission method

dynamic askPermission(
  1. bool isFromPicker,
  2. PermissionType permissionType,
  3. int index
)

Asking permission (Platform specific)

Implementation

askPermission(
    bool isFromPicker, PermissionType permissionType, int index) async {
  Map<Permission, PermissionStatus> statuses = {};

  /// You can request multiple permissions at once.
  if (Platform.isIOS) {
    statuses = await [
      Permission.photos,
      Permission.storage,
    ].request();
  } else {
    statuses = await [
      Permission.camera,
      Permission.storage,

      /// Permission.storage is used in android below sdk version 33 for access storage and gallery
      Permission.photos,
    ].request();
  }
  bool isForStorage = permissionType == PermissionType.storage;
  if (isForStorage) {
    if (Platform.isIOS) {
      ///For iOS we need to access photos

      await Permission.photos.request().then((value) => eventAction(
          isForStorage, isFromPicker, permissionType, index, statuses));
    } else {
      ///For Android we need to access storage

      DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
      AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
      androidInfo.version.sdkInt! >= 33

          ///  current device android sdk version is greater than 33 than we need to request Permission.photos
          ? await Permission.photos.request().then((value) => eventAction(
              isForStorage, isFromPicker, permissionType, index, statuses))
          : Permission.storage.request().then((value) => eventAction(
              isForStorage, isFromPicker, permissionType, index, statuses));
      if (await Permission.storage.isGranted) {
        eventAction(
            isForStorage, isFromPicker, permissionType, index, statuses);
      }
    }
  } else {
    ///If coming from camera then we need to take permission of camera (In both platform)
    await Permission.camera.request().then((value) => eventAction(
        isForStorage, isFromPicker, permissionType, index, statuses));
  }
}