You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Show permission disclosure page and allows required permissions and their associated services before the user can proceed.
5
+
Show permission disclosure page and allows required permissions and their associated services before
6
+
the user can proceed.
5
7
6
-
This package shows a prominent in-app disclosure page for getting permissions as required by [Google Play](https://support.google.com/googleplay/android-developer/answer/9799150?visit_id=638041800350153935-369621111&p=pd-m&rd=1#prominent_disclosure&zippy=%2Cstep-provide-prominent-in-app-disclosure%2Cstep-review-best-practices-for-accessing-location%2Cstep-consider-alternatives-to-accessing-location-in-the-background%2Cstep-make-access-to-location-in-the-background-clear-to-users%2Csee-an-example-of-prominent-in-app-disclosure).
7
-
Also support iOS to ensure a consistent experience.
8
+
This package shows a prominent in-app disclosure page for getting permissions as required
9
+
by [Google Play](https://support.google.com/googleplay/android-developer/answer/9799150?visit_id=638041800350153935-369621111&p=pd-m&rd=1#prominent_disclosure&zippy=%2Cstep-provide-prominent-in-app-disclosure%2Cstep-review-best-practices-for-accessing-location%2Cstep-consider-alternatives-to-accessing-location-in-the-background%2Cstep-make-access-to-location-in-the-background-clear-to-users%2Csee-an-example-of-prominent-in-app-disclosure)
10
+
. Also support iOS to ensure a consistent experience.
8
11
9
-
In addition, permissions and their associated services (e.g. GPS) can be set as "required". If this is set, those required permissions will
10
-
be required and if users denied it, this package will show a customizable dialog and redirect user to the appropriate settings page provided by the native OS.
12
+
In addition, permissions and their associated services (e.g. GPS) can be set as "required". If this
13
+
is set, those required permissions will be required and if users denied it, this package will show a
14
+
customizable dialog and redirect user to the appropriate settings page provided by the native OS.
11
15
12
16
## Setup
17
+
13
18
1. Add the following to `pubspec.yaml`
19
+
14
20
```yaml
15
21
dependencies:
16
22
flutter_force_permission: ^0.1.0
17
23
permission_handler: ^10.2.0
18
24
```
19
-
2. This package depends on [permission_handler](https://pub.dev/packages/permission_handler). Perform setup according to that package.
20
-
3. On Android, if you use `POST_NOTIFICATIONS` permission, update the `targetSdkVersion` in `build.gradle` to at least 33 so that the permission request dialog is shown correctly. Refer to [relevant Android Developer page](https://developer.android.com/develop/ui/views/notifications/notification-permission) for details.
25
+
26
+
2. This package depends on [permission_handler](https://pub.dev/packages/permission_handler).
27
+
Perform setup according to that package.
28
+
3. On Android, if you use `POST_NOTIFICATIONS` permission, update the `targetSdkVersion`
29
+
in `build.gradle` to at least 33 so that the permission request dialog is shown correctly. Refer
30
+
to [relevant Android Developer page](https://developer.android.com/develop/ui/views/notifications/notification-permission)
31
+
for details.
32
+
21
33
```groovy
22
34
android {
23
35
// ...
@@ -29,53 +41,135 @@ android {
29
41
// ...
30
42
}
31
43
```
32
-
4. If any features is required, it is highly recommended to also set the `<uses-feature>` tag in AndroidManifest.xml. Refer to [relevant Android Developers page](https://developer.android.com/guide/topics/manifest/uses-feature-element) for details.
44
+
45
+
4. If any features is required, it is highly recommended to also set the `<uses-feature>` tag in
46
+
AndroidManifest.xml. Refer
47
+
to [relevant Android Developers page](https://developer.android.com/guide/topics/manifest/uses-feature-element)
48
+
for details.
33
49
34
50
## Usage
35
-
1. Create an instance of FlutterForcePermission, providing configuration. Refer to documentation for [FlutterForcePermissionConfig] for details.
51
+
52
+
1. Create an instance of FlutterForcePermission, providing configuration. Refer to documentation
53
+
for [FlutterForcePermissionConfig] for details.
54
+
36
55
```dart
56
+
37
57
final perm = FlutterForcePermission(
38
-
FlutterForcePermissionConfig(
39
-
title: 'Title',
40
-
permissionItemConfigs: [
41
-
PermissionItemConfig(
42
-
permissions: [Permission.locationWhenInUse],
43
-
required: true,
44
-
itemText: PermissionItemText(
45
-
header: 'Foreground Location',
46
-
rationaleText: 'Rationale for Foreground location. Required.',
text: 'Please enable location permission for proper usage.',
70
+
buttonText: 'Settings',
52
71
),
53
72
),
54
-
PermissionItemConfig(
55
-
permissions: [Permission.locationAlways],
56
-
itemText: PermissionItemText(
57
-
header: 'Background Location',
58
-
rationaleText: 'Rationale for Background location. lorem ipsum dolor sit amet.',
59
-
),
73
+
),
74
+
PermissionItemConfig(
75
+
permissions: [Permission.locationAlways],
76
+
itemText: PermissionItemText(
77
+
header: 'Background Location',
78
+
rationaleText: 'Rationale for Background location. lorem ipsum dolor sit amet.',
60
79
),
61
-
],
62
-
),
63
-
);
80
+
),
81
+
],
82
+
),
83
+
);
64
84
```
65
-
2. Show the disclosure page as needed. This method will handle showing the disclosure page and requesting permissions.
66
-
This function takes a [NavigatorState](https://api.flutter.dev/flutter/widgets/NavigatorState-class.html) which can be retrieved through `Navigator.of(context)` call.
67
-
This is an async function. Wrap the function in an `async` block as needed.
68
-
Returns a map of permission and their requested status (granted/denied/etc), service status and whether they are requested by this plugin.
85
+
86
+
2. Show the disclosure page as needed. This method will handle showing the disclosure page and
87
+
requesting permissions. This function takes
88
+
a [NavigatorState](https://api.flutter.dev/flutter/widgets/NavigatorState-class.html) which can
89
+
be retrieved through `Navigator.of(context)` call. This is an async function. Wrap the function
90
+
in an `async` block as needed. Returns a map of permission and their requested status (
91
+
granted/denied/etc), service status and whether they are requested by this plugin.
92
+
69
93
```dart
70
-
final result = await perm.show(Navigator.of(context));
94
+
95
+
final result = await
96
+
perm.show(Navigator.of(context));
71
97
```
72
98
73
99
### Styling
74
-
You can set the style of the text shown by setting up a [TextTheme](https://api.flutter.dev/flutter/material/TextTheme-class.html) of the provided context.
100
+
101
+
You can set the style of the text shown by setting up
102
+
a [TextTheme](https://api.flutter.dev/flutter/material/TextTheme-class.html) of the provided
103
+
context.
104
+
75
105
- Title uses `headline6` text style.
76
106
- Item header use `subtitle1` text style.
77
107
- Item body use `bodyText2` text style.
78
108
109
+
## Advanced Usage
110
+
111
+
### Customize the required permission denied prompt
112
+
113
+
If you wish to customize the dialog shown when the required permission is denied, provide
114
+
a `showDialogCallback` which to show your dialog. Parameters are included for you to compose the
115
+
appropriate dialog. In your callback, you SHOULD:
116
+
117
+
1. Display a non-dismissable dialog. This can be typically achieved by setting `barrierDismissible`
118
+
to false and provide an empty callback e.g. (`() async => false`) to `willPopCallback` for your
119
+
dialog.
120
+
2. Call the provided `callback` parameter in your callback when the user click the confirm button,
0 commit comments