diff --git a/permission_handler/CHANGELOG.md b/permission_handler/CHANGELOG.md index 576f07f1b..579aafebc 100644 --- a/permission_handler/CHANGELOG.md +++ b/permission_handler/CHANGELOG.md @@ -1,3 +1,7 @@ +## 12.0.2 + +- Fixes issue where permission callbacks would fire for incorrect permissions by isolating callbacks per permission instance. + ## 12.0.1 - Updates the correspondence between permission groups and the key values of Info.plist in the README.md. diff --git a/permission_handler/lib/permission_handler.dart b/permission_handler/lib/permission_handler.dart index 4025997eb..66c062f69 100644 --- a/permission_handler/lib/permission_handler.dart +++ b/permission_handler/lib/permission_handler.dart @@ -24,56 +24,57 @@ Future openAppSettings() => _handler.openAppSettings(); /// Actions that can be executed on a permission. extension PermissionActions on Permission { /// Callback for when permission is denied. - static FutureOr? Function()? _onDenied; + static final Map? Function()?> _onDenied = {}; /// Callback for when permission is granted. - static FutureOr? Function()? _onGranted; + static final Map? Function()?> _onGranted = {}; /// Callback for when permission is permanently denied. - static FutureOr? Function()? _onPermanentlyDenied; + static final Map? Function()?> + _onPermanentlyDenied = {}; /// Callback for when permission is restricted. - static FutureOr? Function()? _onRestricted; + static final Map? Function()?> _onRestricted = {}; /// Callback for when permission is limited. - static FutureOr? Function()? _onLimited; + static final Map? Function()?> _onLimited = {}; /// Callback for when permission is Provisional. - static FutureOr? Function()? _onProvisional; + static final Map? Function()?> _onProvisional = {}; /// Method to set a callback for when permission is denied. Permission onDeniedCallback(FutureOr? Function()? callback) { - _onDenied = callback; + _onDenied[this] = callback; return this; } /// Method to set a callback for when permission is granted. Permission onGrantedCallback(FutureOr? Function()? callback) { - _onGranted = callback; + _onGranted[this] = callback; return this; } /// Method to set a callback for when permission is permanently denied. Permission onPermanentlyDeniedCallback(FutureOr? Function()? callback) { - _onPermanentlyDenied = callback; + _onPermanentlyDenied[this] = callback; return this; } /// Method to set a callback for when permission is restricted. Permission onRestrictedCallback(FutureOr? Function()? callback) { - _onRestricted = callback; + _onRestricted[this] = callback; return this; } /// Method to set a callback for when permission is limited. Permission onLimitedCallback(FutureOr? Function()? callback) { - _onLimited = callback; + _onLimited[this] = callback; return this; } /// Method to set a callback for when permission is provisional. Permission onProvisionalCallback(FutureOr? Function()? callback) { - _onProvisional = callback; + _onProvisional[this] = callback; return this; } @@ -109,17 +110,17 @@ extension PermissionActions on Permission { (await [this].request())[this] ?? PermissionStatus.denied; if (permissionStatus.isDenied) { - _onDenied?.call(); + _onDenied[this]?.call(); } else if (permissionStatus.isGranted) { - _onGranted?.call(); + _onGranted[this]?.call(); } else if (permissionStatus.isPermanentlyDenied) { - _onPermanentlyDenied?.call(); + _onPermanentlyDenied[this]?.call(); } else if (permissionStatus.isRestricted) { - _onRestricted?.call(); + _onRestricted[this]?.call(); } else if (permissionStatus.isLimited) { - _onLimited?.call(); + _onLimited[this]?.call(); } else if (permissionStatus.isProvisional) { - _onProvisional?.call(); + _onProvisional[this]?.call(); } return permissionStatus; diff --git a/permission_handler/pubspec.yaml b/permission_handler/pubspec.yaml index 3e0861cd9..1c94a6d59 100644 --- a/permission_handler/pubspec.yaml +++ b/permission_handler/pubspec.yaml @@ -2,7 +2,7 @@ name: permission_handler description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions. repository: https://github.com/baseflow/flutter-permission-handler issue_tracker: https://github.com/Baseflow/flutter-permission-handler/issues -version: 12.0.1 +version: 12.0.2 environment: sdk: ^3.5.0