Baseflow / flutter-permission-plugins

This repo contains a collection of permission related Flutter plugins which can be used to request permissions to access device resources in a cross-platform way.
https://baseflow.com
MIT License
52 stars 34 forks source link

Android Permission Best Practices #30

Open DavidCorrado opened 4 years ago

DavidCorrado commented 4 years ago

🏗 Enhancement Proposal

I have been evaluating the popular location permission libraries with flutter to see how it matches with the best practices. Below is what I found with your library. Let me know if there are ways to get this to work that I missed.

Pitch

Android Best Practices https://developer.android.com/distribute/best-practices/develop/runtime-permissions https://developer.android.com/training/permissions/requesting So below is my understanding of the best practices.

if (Location Services Disabled)
    A) Show Location Services Dialog 
else if (Location Services Enabled)
    If(Permission Denied Forever)
        B) Show Dialog that says permission denied forever and will show Settings
            C) Redirect to app settings
    else if(Denied Once && Permission Rational provided)
        D) Show Permission Rational
                  Show Permission Dialog
    else
        E) Show Permission Dialog

So the library does not support A. The library does not automatically show the location services enable dialog. This library does if you need a code reference https://github.com/loup-v/geolocation B/C. So if permissions are denied forever I would think it would be best to show some sort of dialog before redirecting the user to the settings page. The library does not redirect the user to the settings page or show the dialog before as I think it should. So maybe when requesting permission we can pass this message and you show it in a dialog before going to the settings page. Also might want to expose the neverAskAgain like you have in here https://github.com/Baseflow/flutter-permission-handler/blob/develop/lib/src/permission_enums.dart D. It would be great if when requesting permission that the permission rational could be passed in so your library would show the dialog and after they confirm they get taken to the grant page again.

Summary I think these are the changes required for users of the library to implement permissions. 1) Show enable location services dialog when its disabled 2) Return denied forever from the permissions enum. Give developer option to redirect user to app settings if denied forever. Also show a dialog before redirecting to app settings that the developer can send in the text for. 3) Have permission rational be something we pass in when requesting permissions so the library can handle showing it and showing the grant permission dialog.

Platforms affected (mark all that apply)

DavidCorrado commented 4 years ago

Added a repo with Android and iOS examples of this best practice for review of how this works and for clarification and to validate things I said above are possible https://github.com/DavidCorrado/LocationPermissions

DavidCorrado commented 4 years ago

I created a specific example of how to do what I think is best practices as a flutter plugin here. This example is really specific for my usecase but I think you could make it more flexible for a use in a plugin. Feel free to take any of my code or ideas from this example https://github.com/DavidCorrado/LocationPermissions/tree/master/Flutter/location_services_permissions

Nathan-Heller commented 4 years ago

I'd like to upvote this proposal. I do not believe there is a trivial way to differentiate between 'denied once' and 'denied forever', which makes it difficult to show the appropriate modal dialogs/direct the user to the correct location to update their settings.

Are there any status updates on this proposal (and its sister proposal #31 )?