flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

[Feature request]: Hide platform version details for Permission.photos

Open ChristianEdwardPadilla opened this issue 2 years ago • 2 comments

Is there already an issue requesting this feature?

Please select affected platform(s)

  • [X] Android
  • [X] iOS
  • [X] Windows

Use case

When using permission_handler to check for photos permission you must check the platform and the Android version like so:

if (Platform.isAndroid) {
  final androidInfo = await DeviceInfoPlugin().androidInfo;
  if (androidInfo.version.sdkInt <= 32) {
    /// use [Permission.storage]
  }  else {
    /// use [Permission.photos]
  }
}

This is explained in the documentation for Permission.photos here. This runs against the design goal of Flutter plugins to hide platform-specific details whenever possible.

Proposal

I propose that Permission.photos should be changed to do the platform and Android version checks itself so that it behaves as expected on lower Android versions.

This would be a breaking change, but it would serve to fix this issue and seems worth it since most users of this plugin are in the future.

Specific requirements or considerations

No response

Additional information or context

No response

ChristianEdwardPadilla avatar Sep 10 '23 15:09 ChristianEdwardPadilla

FYI in the meantime we are considering adding an extension something like this:

extension PermissionExtension on Permission {
  static Future<Permission> get photosOrStorage async {
    final androidInfo = await DeviceInfoPlugin().androidInfo;
    final isAndroidTPlus = (androidInfo.version.sdkInt ?? 0) >= 33;
    if (isAndroidTPlus) {
      return Permission.photos;
    } else {
      return Permission.storage;
    }
  }
}

But it would be better to come from permission_handler itself, IMO. The cross-plugin dependency on device_info_plus is not ideal here.

ChristianEdwardPadilla avatar Oct 18 '23 17:10 ChristianEdwardPadilla

Dear @ChristianEdwardPadilla,

Thanks for submitting this feature. We discussed this feature request in the team and we decided to label this issue as an enhancement. We are working on a refactor of the permission handler. During the refactor we well be handling this feature request.

Kind regards,

TimHoogstrate avatar Oct 19 '23 12:10 TimHoogstrate