https://github.com/dev-hwang/permission_request_page
A widget that explains and requests why app permissions are needed.
https://github.com/dev-hwang/permission_request_page
android flutter ios permission
Last synced: 9 months ago
JSON representation
A widget that explains and requests why app permissions are needed.
- Host: GitHub
- URL: https://github.com/dev-hwang/permission_request_page
- Owner: Dev-hwang
- License: mit
- Created: 2022-09-02T10:53:05.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-14T06:14:20.000Z (about 2 years ago)
- Last Synced: 2025-01-31T21:34:43.647Z (over 1 year ago)
- Topics: android, flutter, ios, permission
- Language: Dart
- Homepage: https://pub.dev/packages/permission_request_page
- Size: 134 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Is it annoying to create a page that explains permissions to users or implement permission request
functionality? If so, try this plugin! This plugin simplifies the implementation of the above
features. If you don't like the default template, you can customize it using the builder defined
in `PermissionRequestPage`.

## Getting started
To use this plugin, add `permission_request_page` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/). For example:
```yaml
dependencies:
permission_request_page: ^2.0.0
```
## How to use
Declare the required permissions in your app.
```dart
const List _kPermission = [
PermissionData(
permissionType: PermissionType.location,
permissionName: 'Location',
description: 'Permission for accessing the device\'s location.',
isNecessary: true,
),
PermissionData(
permissionType: PermissionType.storage,
permissionName: 'Storage',
description: 'Permission for accessing external storage.',
isNecessary: false,
),
PermissionData(
permissionType: PermissionType.notification,
permissionName: 'Notification',
description: 'Permission for pushing notifications.',
isNecessary: false,
),
];
```
```dart
const CustomText _kCustomText = CustomText(
permissionViewHeaderText: 'The following permissions are required to use the application.',
permissionRequestButtonText: 'NEXT',
popupTextWhenPermissionDenied: 'To use the application, you must grant the following permissions: ',
);
```
Write an init function to execute when all required permissions are granted.
```dart
class _SplashPageState extends State {
Future _initFunction() async {
InitResult initResult;
try {
// Write your app initialization code.
initResult = const InitResult(complete: true);
} catch (error, stackTrace) {
// Write code to handle app initialization errors.
initResult =
InitResult(complete: false, error: error, stackTrace: stackTrace);
}
// If the complete value of InitResult is true, it navigates to the nextPage.
return initResult;
}
@override
Widget build(BuildContext context) {
// ...
}
}
```
Add a PermissionRequestPage widget under Scaffold.
```dart
class _SplashPageState extends State {
Future _initFunction() async {
// ...
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: PermissionRequestPage(
permissions: _kPermission,
customText: _kCustomText,
initFunction: _initFunction,
nextPage: Container(),
),
);
}
}
```
Declare the permissions to use for each platform.
### :baby_chick: Android
/android/app/src/main/AndroidManifest.xml
```xml
```
### :baby_chick: iOS
/ios/Runner/info.plist
```xml
NSCalendarsUsageDescription
description
NSCameraUsageDescription
description
NSContactsUsageDescription
description
NSLocationWhenInUseUsageDescription
description
NSLocationAlwaysAndWhenInUseUsageDescription
description
NSLocationUsageDescription
description
NSLocationAlwaysUsageDescription
description
NSMicrophoneUsageDescription
description
NSPhotoLibraryUsageDescription
description
NSAppleMusicUsageDescription
description
kTCCServiceMediaLibrary
description
NSMotionUsageDescription
description
NSSpeechRecognitionUsageDescription
description
NSRemindersUsageDescription
description
```
/ios/Podfile
```
post_install do |installer|
installer.pods_project.targets.each do |target|
# Add
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
# See the table below to add macros for permissions to use in your app.
'PERMISSION_LOCATION=1',
'PERMISSION_NOTIFICATIONS=1'
]
end
flutter_additional_ios_build_settings(target)
end
end
```
| Permission | Info.plist | Macro |
|-----------------------------|---------------------------------------------------------------------------------------------------------------|------------------------------|
| PermissionType.calendar | NSCalendarsUsageDescription | PERMISSION_EVENTS |
| PermissionType.reminders | NSRemindersUsageDescription | PERMISSION_REMINDERS |
| PermissionType.contacts | NSContactsUsageDescription | PERMISSION_CONTACTS |
| PermissionType.camera | NSCameraUsageDescription | PERMISSION_CAMERA |
| PermissionType.microphone | NSMicrophoneUsageDescription | PERMISSION_MICROPHONE |
| PermissionType.speech | NSSpeechRecognitionUsageDescription | PERMISSION_SPEECH_RECOGNIZER |
| PermissionType.photos | NSPhotoLibraryUsageDescription | PERMISSION_PHOTOS |
| PermissionType.location | NSLocationUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription | PERMISSION_LOCATION |
| PermissionType.notification | PermissionGroupNotification | PERMISSION_NOTIFICATIONS |
| PermissionType.mediaLibrary | NSAppleMusicUsageDescription, kTCCServiceMediaLibrary | PERMISSION_MEDIA_LIBRARY |
| PermissionType.sensors | NSMotionUsageDescription | PERMISSION_SENSORS |
| PermissionType.bluetooth | NSBluetoothAlwaysUsageDescription, NSBluetoothPeripheralUsageDescription | PERMISSION_BLUETOOTH |
## Support
If you find any bugs or issues while using the plugin, please register an issues on [GitHub](https://github.com/Dev-hwang/permission_request_page/issues). You can also contact us at .