From ceac713b81f55a2cc37653ad533c433ca016c9cf Mon Sep 17 00:00:00 2001 From: Hari07 <22373191+Hari-07@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:18:32 +0400 Subject: [PATCH 1/6] Handle contacts limited permission (#1395) * Handle contacts limited permission * Version bump and comments --- permission_handler/lib/permission_handler.dart | 4 ++-- permission_handler_apple/CHANGELOG.md | 4 ++++ .../ios/Classes/strategies/ContactPermissionStrategy.m | 5 ++++- permission_handler_apple/pubspec.yaml | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/permission_handler/lib/permission_handler.dart b/permission_handler/lib/permission_handler.dart index 31db1936e..4025997eb 100644 --- a/permission_handler/lib/permission_handler.dart +++ b/permission_handler/lib/permission_handler.dart @@ -140,8 +140,8 @@ extension PermissionCheckShortcuts on Permission { /// *Only supported on iOS.* Future get isRestricted => status.isRestricted; - /// User has authorized this application for limited photo library access. - /// *Only supported on iOS.(iOS14+)* + /// User has authorized this application for limited access. + /// *Only supported on iOS.(iOS14+ for photos, ios18+ for contacts)* Future get isLimited => status.isLimited; /// Returns `true` when permissions are denied permanently. diff --git a/permission_handler_apple/CHANGELOG.md b/permission_handler_apple/CHANGELOG.md index 05dd219d7..20a65108a 100644 --- a/permission_handler_apple/CHANGELOG.md +++ b/permission_handler_apple/CHANGELOG.md @@ -1,3 +1,7 @@ +## 9.4.6 + +* Adds the ability to handle `CNAuthorizationStatusLimited` introduced in ios18 + ## 9.4.5 * Fixes issue #1002, Xcode warning of the unresponsive of main thread when checking isLocationEnabled. diff --git a/permission_handler_apple/ios/Classes/strategies/ContactPermissionStrategy.m b/permission_handler_apple/ios/Classes/strategies/ContactPermissionStrategy.m index 67b45b4ad..37ff452d0 100644 --- a/permission_handler_apple/ios/Classes/strategies/ContactPermissionStrategy.m +++ b/permission_handler_apple/ios/Classes/strategies/ContactPermissionStrategy.m @@ -45,6 +45,8 @@ + (PermissionStatus)permissionStatus { return PermissionStatusPermanentlyDenied; case CNAuthorizationStatusAuthorized: return PermissionStatusGranted; + case CNAuthorizationStatusLimited: + return PermissionStatusLimited; } } else { @@ -73,7 +75,8 @@ + (void)requestPermissionsFromContactStore:(PermissionStatusHandler)completionHa [contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError *__nullable error) { if (granted) { - completionHandler(PermissionStatusGranted); + const PermissionStatus updatedStatus = [self permissionStatus]; + completionHandler(updatedStatus); } else { completionHandler(PermissionStatusPermanentlyDenied); } diff --git a/permission_handler_apple/pubspec.yaml b/permission_handler_apple/pubspec.yaml index ef6679c56..c0a3fb49f 100644 --- a/permission_handler_apple/pubspec.yaml +++ b/permission_handler_apple/pubspec.yaml @@ -2,7 +2,7 @@ name: permission_handler_apple description: Permission plugin for Flutter. This plugin provides the iOS 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: 9.4.5 +version: 9.4.6 environment: sdk: ">=2.15.0 <4.0.0" From 7952bc1f459e18d8be05316e08d01776ddb59d43 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 20 Feb 2025 10:20:50 +0100 Subject: [PATCH 2/6] Resolve build errors and update example project --- .../example/lib/main.dart | 122 ++++++++++-------- permission_handler_apple/example/pubspec.yaml | 2 +- 2 files changed, 69 insertions(+), 55 deletions(-) diff --git a/permission_handler_apple/example/lib/main.dart b/permission_handler_apple/example/lib/main.dart index f35cf7592..4750f1ac5 100644 --- a/permission_handler_apple/example/lib/main.dart +++ b/permission_handler_apple/example/lib/main.dart @@ -3,24 +3,32 @@ import 'package:flutter/material.dart'; import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'; void main() { - runApp(BaseflowPluginExample( + runApp( + BaseflowPluginExample( pluginName: 'Permission Handler', githubURL: 'https://github.com/Baseflow/flutter-permission-handler', pubDevURL: 'https://pub.dev/packages/permission_handler', - pages: [PermissionHandlerWidget.createPage()])); + pages: [PermissionHandlerWidget.createPage()], + ), + ); } ///Defines the main theme color final MaterialColor themeMaterialColor = BaseflowPluginExample.createMaterialColor( - const Color.fromRGBO(48, 49, 60, 1)); + const Color.fromRGBO(48, 49, 60, 1), + ); /// A Flutter application demonstrating the functionality of this plugin class PermissionHandlerWidget extends StatefulWidget { + const PermissionHandlerWidget._(); + /// Create a page containing the functionality of this plugin static ExamplePage createPage() { return ExamplePage( - Icons.location_on, (context) => PermissionHandlerWidget()); + Icons.location_on, + (context) => const PermissionHandlerWidget._(), + ); } @override @@ -33,29 +41,31 @@ class _PermissionHandlerWidgetState extends State { Widget build(BuildContext context) { return Center( child: ListView( - children: Permission.values - .where((permission) { - return permission != Permission.unknown && - permission != Permission.phone && - permission != Permission.sms && - permission != Permission.ignoreBatteryOptimizations && - permission != Permission.accessMediaLocation && - permission != Permission.activityRecognition && - permission != Permission.manageExternalStorage && - permission != Permission.systemAlertWindow && - permission != Permission.requestInstallPackages && - permission != Permission.accessNotificationPolicy && - permission != Permission.bluetoothScan && - permission != Permission.bluetoothAdvertise && - permission != Permission.bluetoothConnect && - permission != Permission.nearbyWifiDevices && - permission != Permission.videos && - permission != Permission.audio && - permission != Permission.scheduleExactAlarm && - permission != Permission.sensorsAlways; - }) - .map((permission) => PermissionWidget(permission)) - .toList()), + children: + Permission.values + .where((permission) { + return permission != Permission.unknown && + permission != Permission.phone && + permission != Permission.sms && + permission != Permission.ignoreBatteryOptimizations && + permission != Permission.accessMediaLocation && + permission != Permission.activityRecognition && + permission != Permission.manageExternalStorage && + permission != Permission.systemAlertWindow && + permission != Permission.requestInstallPackages && + permission != Permission.accessNotificationPolicy && + permission != Permission.bluetoothScan && + permission != Permission.bluetoothAdvertise && + permission != Permission.bluetoothConnect && + permission != Permission.nearbyWifiDevices && + permission != Permission.videos && + permission != Permission.audio && + permission != Permission.scheduleExactAlarm && + permission != Permission.sensorsAlways; + }) + .map((permission) => PermissionWidget(permission)) + .toList(), + ), ); } } @@ -63,18 +73,16 @@ class _PermissionHandlerWidgetState extends State { /// Permission widget containing information about the passed [Permission] class PermissionWidget extends StatefulWidget { /// Constructs a [PermissionWidget] for the supplied [Permission] - const PermissionWidget(this._permission); + const PermissionWidget(this.permission, {super.key}); - final Permission _permission; + /// The [Permission] that this widget is rendered for. + final Permission permission; @override - State createState() => _PermissionState(_permission); + State createState() => _PermissionState(); } class _PermissionState extends State { - _PermissionState(this._permission); - - final Permission _permission; final PermissionHandlerPlatform _permissionHandler = PermissionHandlerPlatform.instance; PermissionStatus _permissionStatus = PermissionStatus.denied; @@ -87,7 +95,9 @@ class _PermissionState extends State { } void _listenForPermissionStatus() async { - final status = await _permissionHandler.checkPermissionStatus(_permission); + final status = await _permissionHandler.checkPermissionStatus( + widget.permission, + ); setState(() => _permissionStatus = status); } @@ -108,45 +118,49 @@ class _PermissionState extends State { Widget build(BuildContext context) { return ListTile( title: Text( - _permission.toString(), + widget.permission.toString(), style: Theme.of(context).textTheme.bodyLarge, ), subtitle: Text( _permissionStatus.toString(), style: TextStyle(color: getPermissionColor()), ), - trailing: (_permission is PermissionWithService) - ? IconButton( - icon: const Icon( - Icons.info, - color: Colors.white, - ), - onPressed: () { - checkServiceStatus( - context, _permission as PermissionWithService); - }) - : null, + trailing: + (widget.permission is PermissionWithService) + ? IconButton( + icon: const Icon(Icons.info, color: Colors.white), + onPressed: () { + checkServiceStatus( + context, + widget.permission as PermissionWithService, + ); + }, + ) + : null, onTap: () { - requestPermission(_permission); + requestPermission(widget.permission); }, ); } void checkServiceStatus( - BuildContext context, PermissionWithService permission) async { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text( - (await _permissionHandler.checkServiceStatus(permission)).toString()), - )); + BuildContext context, + PermissionWithService permission, + ) async { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + (await _permissionHandler.checkServiceStatus(permission)).toString(), + ), + ), + ); } Future requestPermission(Permission permission) async { final status = await _permissionHandler.requestPermissions([permission]); setState(() { - print(status); _permissionStatus = status[permission] ?? PermissionStatus.denied; - print(_permissionStatus); }); } } diff --git a/permission_handler_apple/example/pubspec.yaml b/permission_handler_apple/example/pubspec.yaml index 1a9636230..81b6f2dc4 100644 --- a/permission_handler_apple/example/pubspec.yaml +++ b/permission_handler_apple/example/pubspec.yaml @@ -2,7 +2,7 @@ name: permission_handler_apple_example description: Demonstrates how to use the permission_handler_apple plugin. environment: - sdk: ">=2.15.0 <3.0.0" + sdk: ^3.7.0 dependencies: baseflow_plugin_template: ^2.1.1 From 8151ece4363b73dff8269a1a77a810c95c195f55 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 20 Feb 2025 10:28:38 +0100 Subject: [PATCH 3/6] Update build configuration to use macos-latest --- .github/workflows/permission_handler.yaml | 28 ++++++++----------- .../workflows/permission_handler_apple.yaml | 6 +--- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.github/workflows/permission_handler.yaml b/.github/workflows/permission_handler.yaml index 4c7fe1df9..8d2bede24 100644 --- a/.github/workflows/permission_handler.yaml +++ b/.github/workflows/permission_handler.yaml @@ -6,15 +6,15 @@ name: permission_handler # events but only for the main branch on: push: - branches: [ main ] + branches: [main] paths: - - 'permission_handler/**' - - '.github/workflows/permission_handler.yaml' + - "permission_handler/**" + - ".github/workflows/permission_handler.yaml" pull_request: - branches: [ main ] + branches: [main] paths: - - 'permission_handler/**' - - '.github/workflows/permission_handler.yaml' + - "permission_handler/**" + - ".github/workflows/permission_handler.yaml" # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -22,14 +22,10 @@ jobs: name: App facing package # The type of runner that the job will run on - # - # TODO(mvanbeusekom): Manually set to macOS 13 to support Xcode 15 and iOS 17 SDKs. - # Currently `macos-latest` is based on macOS 12 and doesn't support iOS 17 SDK. This - # should be moved back to `macos-latest` when GitHub Actions images are updated. - runs-on: macos-13 + runs-on: macos-latest env: - source-directory: ./permission_handler + source-directory: ./permission_handler example-directory: ./permission_handler/example # Steps represent a sequence of tasks that will be executed as part of the job @@ -47,13 +43,13 @@ jobs: # Make sure JAVA version 17 is installed on build agent. - uses: actions/setup-java@v3 with: - distribution: 'temurin' # See 'Supported distributions' for available options - java-version: '17' + distribution: "temurin" # See 'Supported distributions' for available options + java-version: "17" # Make sure the stable version of Flutter is available - uses: subosito/flutter-action@v2 with: - channel: 'stable' + channel: "stable" # Download all Flutter packages - name: Download dependencies @@ -64,7 +60,7 @@ jobs: - name: Run Dart Format run: dart format --set-exit-if-changed . working-directory: ${{env.source-directory}} - + # Run Flutter Analyzer - name: Run Flutter Analyzer run: flutter analyze diff --git a/.github/workflows/permission_handler_apple.yaml b/.github/workflows/permission_handler_apple.yaml index 966f1c318..8832b18dd 100644 --- a/.github/workflows/permission_handler_apple.yaml +++ b/.github/workflows/permission_handler_apple.yaml @@ -22,11 +22,7 @@ jobs: name: Apple platform package # The type of runner that the job will run on - # - # TODO(mvanbeusekom): Manually set to macOS 13 to support Xcode 15 and iOS 17 SDKs. - # Currently `macos-latest` is based on macOS 12 and doesn't support iOS 17 SDK. This - # should be moved back to `macos-latest` when GitHub Actions images are updated. - runs-on: macos-13 + runs-on: macos-latest env: source-directory: ./permission_handler_apple From 8ae1bda9b1cb65bbc692df9f5b1e7380d4b8b327 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 20 Feb 2025 10:52:11 +0100 Subject: [PATCH 4/6] Only handle CNAuthorizationLimited on iOS 18+ --- .../strategies/ContactPermissionStrategy.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/permission_handler_apple/ios/Classes/strategies/ContactPermissionStrategy.m b/permission_handler_apple/ios/Classes/strategies/ContactPermissionStrategy.m index 37ff452d0..49b6dd3f9 100644 --- a/permission_handler_apple/ios/Classes/strategies/ContactPermissionStrategy.m +++ b/permission_handler_apple/ios/Classes/strategies/ContactPermissionStrategy.m @@ -33,7 +33,7 @@ - (void)requestPermission:(PermissionGroup)permission completionHandler:(Permiss } + (PermissionStatus)permissionStatus { - if (@available(iOS 9.0, *)) { + if (@available(iOS 18.0, *)) { CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; switch (status) { @@ -48,7 +48,21 @@ + (PermissionStatus)permissionStatus { case CNAuthorizationStatusLimited: return PermissionStatusLimited; } + } else if (@available(iOS 9.0, *)) { + CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; + switch (status) { + case CNAuthorizationStatusNotDetermined: + return PermissionStatusDenied; + case CNAuthorizationStatusRestricted: + return PermissionStatusRestricted; + case CNAuthorizationStatusDenied: + return PermissionStatusPermanentlyDenied; + case CNAuthorizationStatusAuthorized: + return PermissionStatusGranted; + default: + return PermissionStatusGranted; + } } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" From d5222915a6c6e492cacd9a7d832c2f51a3eb3d3c Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 20 Feb 2025 11:22:16 +0100 Subject: [PATCH 5/6] Force build workflow to use macOS 15 --- .github/workflows/permission_handler.yaml | 13 ++++---- .../workflows/permission_handler_apple.yaml | 30 ++++++++----------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/.github/workflows/permission_handler.yaml b/.github/workflows/permission_handler.yaml index 8d2bede24..340849441 100644 --- a/.github/workflows/permission_handler.yaml +++ b/.github/workflows/permission_handler.yaml @@ -22,7 +22,11 @@ jobs: name: App facing package # The type of runner that the job will run on - runs-on: macos-latest + # + # TODO(mvanbeusekom): Manually set to macOS 15 to support Xcode 16 and iOS 18 SDKs. + # Currently `macos-latest` is based on macOS 14 and doesn't support iOS 18 SDK. This + # should be moved back to `macos-latest` when GitHub Actions images are updated. + runs-on: macos-15 env: source-directory: ./permission_handler @@ -33,13 +37,6 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - # Override current Xcode version with version 15.0.1. - # - # TODO(mvanbeusekom): Remove when the macos-latest image supports version 15.0.1 - # out of the box (see https://github.com/actions/runner-images/blob/main/README.md). - - name: Select Xcode version - run: sudo xcode-select -s '/Applications/Xcode_15.0.1.app/Contents/Developer' - # Make sure JAVA version 17 is installed on build agent. - uses: actions/setup-java@v3 with: diff --git a/.github/workflows/permission_handler_apple.yaml b/.github/workflows/permission_handler_apple.yaml index 8832b18dd..5540a042c 100644 --- a/.github/workflows/permission_handler_apple.yaml +++ b/.github/workflows/permission_handler_apple.yaml @@ -6,15 +6,15 @@ name: permission_handler_apple # events but only for the main branch on: push: - branches: [ main ] + branches: [main] paths: - - 'permission_handler_apple/**' - - '.github/workflows/permission_handler_apple.yaml' + - "permission_handler_apple/**" + - ".github/workflows/permission_handler_apple.yaml" pull_request: - branches: [ main ] + branches: [main] paths: - - 'permission_handler_apple/**' - - '.github/workflows/permission_handler_apple.yaml' + - "permission_handler_apple/**" + - ".github/workflows/permission_handler_apple.yaml" # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -22,28 +22,25 @@ jobs: name: Apple platform package # The type of runner that the job will run on - runs-on: macos-latest + # + # TODO(mvanbeusekom): Manually set to macOS 15 to support Xcode 16 and iOS 18 SDKs. + # Currently `macos-latest` is based on macOS 14 and doesn't support iOS 18 SDK. This + # should be moved back to `macos-latest` when GitHub Actions images are updated. + runs-on: macos-15 env: source-directory: ./permission_handler_apple - example-directory: ./permission_handler_apple/example + example-directory: ./permission_handler_apple/example # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - # Override current Xcode version with version 15.0.1. - # - # TODO(mvanbeusekom): Remove when the macos-latest image supports version 15.0.1 - # out of the box (see https://github.com/actions/runner-images/blob/main/README.md). - - name: Select Xcode version - run: sudo xcode-select -s '/Applications/Xcode_15.0.1.app/Contents/Developer' - # Make sure the stable version of Flutter is available - uses: subosito/flutter-action@v2 with: - channel: 'stable' + channel: "stable" # Download all Flutter packages - name: Download dependencies @@ -64,4 +61,3 @@ jobs: - name: Run iOS build run: flutter build ios --no-codesign --release working-directory: ${{env.example-directory}} - From 847d6288e8c892b3cda3a59816c0e6c0fd1428ec Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Thu, 20 Feb 2025 14:07:18 +0100 Subject: [PATCH 6/6] Upgrade Example app --- permission_handler/example/lib/main.dart | 137 ++++++++++++----------- permission_handler/example/pubspec.yaml | 2 +- 2 files changed, 75 insertions(+), 64 deletions(-) diff --git a/permission_handler/example/lib/main.dart b/permission_handler/example/lib/main.dart index b1615f332..e453216ee 100644 --- a/permission_handler/example/lib/main.dart +++ b/permission_handler/example/lib/main.dart @@ -5,24 +5,32 @@ import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; void main() { - runApp(BaseflowPluginExample( + runApp( + BaseflowPluginExample( pluginName: 'Permission Handler', githubURL: 'https://github.com/Baseflow/flutter-permission-handler', pubDevURL: 'https://pub.dev/packages/permission_handler', - pages: [PermissionHandlerWidget.createPage()])); + pages: [PermissionHandlerWidget.createPage()], + ), + ); } ///Defines the main theme color final MaterialColor themeMaterialColor = BaseflowPluginExample.createMaterialColor( - const Color.fromRGBO(48, 49, 60, 1)); + const Color.fromRGBO(48, 49, 60, 1), + ); /// A Flutter application demonstrating the functionality of this plugin class PermissionHandlerWidget extends StatefulWidget { + const PermissionHandlerWidget._(); + /// Create a page containing the functionality of this plugin static ExamplePage createPage() { return ExamplePage( - Icons.location_on, (context) => PermissionHandlerWidget()); + Icons.location_on, + (context) => const PermissionHandlerWidget._(), + ); } @override @@ -35,40 +43,42 @@ class _PermissionHandlerWidgetState extends State { Widget build(BuildContext context) { return Center( child: ListView( - children: Permission.values - .where((permission) { - if (Platform.isIOS) { - return permission != Permission.unknown && - permission != Permission.phone && - permission != Permission.sms && - permission != Permission.ignoreBatteryOptimizations && - permission != Permission.accessMediaLocation && - permission != Permission.activityRecognition && - permission != Permission.manageExternalStorage && - permission != Permission.systemAlertWindow && - permission != Permission.requestInstallPackages && - permission != Permission.accessNotificationPolicy && - permission != Permission.bluetoothScan && - permission != Permission.bluetoothAdvertise && - permission != Permission.bluetoothConnect && - permission != Permission.nearbyWifiDevices && - permission != Permission.videos && - permission != Permission.audio && - permission != Permission.scheduleExactAlarm && - permission != Permission.sensorsAlways; - } else { - return permission != Permission.unknown && - permission != Permission.mediaLibrary && - permission != Permission.photosAddOnly && - permission != Permission.reminders && - permission != Permission.bluetooth && - permission != Permission.appTrackingTransparency && - permission != Permission.criticalAlerts && - permission != Permission.assistant; - } - }) - .map((permission) => PermissionWidget(permission)) - .toList()), + children: + Permission.values + .where((permission) { + if (Platform.isIOS) { + return permission != Permission.unknown && + permission != Permission.phone && + permission != Permission.sms && + permission != Permission.ignoreBatteryOptimizations && + permission != Permission.accessMediaLocation && + permission != Permission.activityRecognition && + permission != Permission.manageExternalStorage && + permission != Permission.systemAlertWindow && + permission != Permission.requestInstallPackages && + permission != Permission.accessNotificationPolicy && + permission != Permission.bluetoothScan && + permission != Permission.bluetoothAdvertise && + permission != Permission.bluetoothConnect && + permission != Permission.nearbyWifiDevices && + permission != Permission.videos && + permission != Permission.audio && + permission != Permission.scheduleExactAlarm && + permission != Permission.sensorsAlways; + } else { + return permission != Permission.unknown && + permission != Permission.mediaLibrary && + permission != Permission.photosAddOnly && + permission != Permission.reminders && + permission != Permission.bluetooth && + permission != Permission.appTrackingTransparency && + permission != Permission.criticalAlerts && + permission != Permission.assistant; + } + }) + .map((permission) => PermissionWidget(permission)) + .toList(), + ), ); } } @@ -76,18 +86,18 @@ class _PermissionHandlerWidgetState extends State { /// Permission widget containing information about the passed [Permission] class PermissionWidget extends StatefulWidget { /// Constructs a [PermissionWidget] for the supplied [Permission] - const PermissionWidget(this._permission); + const PermissionWidget(this.permission, {super.key}); - final Permission _permission; + /// The [Permission] for which this widget is rendered. + final Permission permission; @override - _PermissionState createState() => _PermissionState(_permission); + _PermissionState createState() => _PermissionState(); } class _PermissionState extends State { - _PermissionState(this._permission); + _PermissionState(); - final Permission _permission; PermissionStatus _permissionStatus = PermissionStatus.denied; @override @@ -98,7 +108,7 @@ class _PermissionState extends State { } void _listenForPermissionStatus() async { - final status = await _permission.status; + final status = await widget.permission.status; setState(() => _permissionStatus = status); } @@ -119,44 +129,45 @@ class _PermissionState extends State { Widget build(BuildContext context) { return ListTile( title: Text( - _permission.toString(), + widget.permission.toString(), style: Theme.of(context).textTheme.bodyLarge, ), subtitle: Text( _permissionStatus.toString(), style: TextStyle(color: getPermissionColor()), ), - trailing: (_permission is PermissionWithService) - ? IconButton( - icon: const Icon( - Icons.info, - color: Colors.white, - ), - onPressed: () { - checkServiceStatus( - context, _permission as PermissionWithService); - }) - : null, + trailing: + (widget.permission is PermissionWithService) + ? IconButton( + icon: const Icon(Icons.info, color: Colors.white), + onPressed: () { + checkServiceStatus( + context, + widget.permission as PermissionWithService, + ); + }, + ) + : null, onTap: () { - requestPermission(_permission); + requestPermission(widget.permission); }, ); } void checkServiceStatus( - BuildContext context, PermissionWithService permission) async { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text((await permission.serviceStatus).toString()), - )); + BuildContext context, + PermissionWithService permission, + ) async { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text((await permission.serviceStatus).toString())), + ); } Future requestPermission(Permission permission) async { final status = await permission.request(); setState(() { - print(status); _permissionStatus = status; - print(_permissionStatus); }); } } diff --git a/permission_handler/example/pubspec.yaml b/permission_handler/example/pubspec.yaml index f72dbeae5..51bff653f 100644 --- a/permission_handler/example/pubspec.yaml +++ b/permission_handler/example/pubspec.yaml @@ -2,7 +2,7 @@ name: permission_handler_example description: Demonstrates how to use the permission_handler plugin. environment: - sdk: ">=2.15.0 <4.0.0" + sdk: ^3.7.0 dependencies: baseflow_plugin_template: ^2.1.1