Skip to content

Commit 1584721

Browse files
mvanbeusekomHenri Van Rooy
authored andcommitted
Updates permission_handler version to 12.0.1
1 parent d842345 commit 1584721

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

permission_handler/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 12.0.2
2+
3+
- Fixes issue where permission callbacks would fire for incorrect permissions by isolating callbacks per permission instance.
4+
15
## 12.0.1
26

37
- Updates the correspondence between permission groups and the key values of Info.plist in the README.md.

permission_handler/lib/permission_handler.dart

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,56 +24,57 @@ Future<bool> openAppSettings() => _handler.openAppSettings();
2424
/// Actions that can be executed on a permission.
2525
extension PermissionActions on Permission {
2626
/// Callback for when permission is denied.
27-
static FutureOr<void>? Function()? _onDenied;
27+
static final Map<Permission, FutureOr<void>? Function()?> _onDenied = {};
2828

2929
/// Callback for when permission is granted.
30-
static FutureOr<void>? Function()? _onGranted;
30+
static final Map<Permission, FutureOr<void>? Function()?> _onGranted = {};
3131

3232
/// Callback for when permission is permanently denied.
33-
static FutureOr<void>? Function()? _onPermanentlyDenied;
33+
static final Map<Permission,
34+
FutureOr<void>? Function()?> _onPermanentlyDenied = {};
3435

3536
/// Callback for when permission is restricted.
36-
static FutureOr<void>? Function()? _onRestricted;
37+
static final Map<Permission, FutureOr<void>? Function()?> _onRestricted = {};
3738

3839
/// Callback for when permission is limited.
39-
static FutureOr<void>? Function()? _onLimited;
40+
static final Map<Permission, FutureOr<void>? Function()?> _onLimited = {};
4041

4142
/// Callback for when permission is Provisional.
42-
static FutureOr<void>? Function()? _onProvisional;
43+
static final Map<Permission, FutureOr<void>? Function()?> _onProvisional = {};
4344

4445
/// Method to set a callback for when permission is denied.
4546
Permission onDeniedCallback(FutureOr<void>? Function()? callback) {
46-
_onDenied = callback;
47+
_onDenied[this] = callback;
4748
return this;
4849
}
4950

5051
/// Method to set a callback for when permission is granted.
5152
Permission onGrantedCallback(FutureOr<void>? Function()? callback) {
52-
_onGranted = callback;
53+
_onGranted[this] = callback;
5354
return this;
5455
}
5556

5657
/// Method to set a callback for when permission is permanently denied.
5758
Permission onPermanentlyDeniedCallback(FutureOr<void>? Function()? callback) {
58-
_onPermanentlyDenied = callback;
59+
_onPermanentlyDenied[this] = callback;
5960
return this;
6061
}
6162

6263
/// Method to set a callback for when permission is restricted.
6364
Permission onRestrictedCallback(FutureOr<void>? Function()? callback) {
64-
_onRestricted = callback;
65+
_onRestricted[this] = callback;
6566
return this;
6667
}
6768

6869
/// Method to set a callback for when permission is limited.
6970
Permission onLimitedCallback(FutureOr<void>? Function()? callback) {
70-
_onLimited = callback;
71+
_onLimited[this] = callback;
7172
return this;
7273
}
7374

7475
/// Method to set a callback for when permission is provisional.
7576
Permission onProvisionalCallback(FutureOr<void>? Function()? callback) {
76-
_onProvisional = callback;
77+
_onProvisional[this] = callback;
7778
return this;
7879
}
7980

@@ -109,17 +110,17 @@ extension PermissionActions on Permission {
109110
(await [this].request())[this] ?? PermissionStatus.denied;
110111

111112
if (permissionStatus.isDenied) {
112-
_onDenied?.call();
113+
_onDenied[this]?.call();
113114
} else if (permissionStatus.isGranted) {
114-
_onGranted?.call();
115+
_onGranted[this]?.call();
115116
} else if (permissionStatus.isPermanentlyDenied) {
116-
_onPermanentlyDenied?.call();
117+
_onPermanentlyDenied[this]?.call();
117118
} else if (permissionStatus.isRestricted) {
118-
_onRestricted?.call();
119+
_onRestricted[this]?.call();
119120
} else if (permissionStatus.isLimited) {
120-
_onLimited?.call();
121+
_onLimited[this]?.call();
121122
} else if (permissionStatus.isProvisional) {
122-
_onProvisional?.call();
123+
_onProvisional[this]?.call();
123124
}
124125

125126
return permissionStatus;

permission_handler/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: permission_handler
22
description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
33
repository: https://github.com/baseflow/flutter-permission-handler
44
issue_tracker: https://github.com/Baseflow/flutter-permission-handler/issues
5-
version: 12.0.1
5+
version: 12.0.2
66

77
environment:
88
sdk: ^3.5.0

0 commit comments

Comments
 (0)