gt_permission 1.1.0
gt_permission: ^1.1.0 copied to clipboard
A comprehensive Flutter permission handler utility with singleton pattern, platform-specific version handling, error management, and user-friendly result objects for all iOS and Android permissions.
GT Permission #
A comprehensive Flutter permission handler utility with singleton pattern, platform-specific version handling, and user-friendly result objects for all iOS and Android permissions.
Features #
- 🔐 Singleton Pattern - Easy access throughout your app
- 📱 Platform-Specific Handling - Android 13+, iOS 14+ version-aware
- 📊 Rich Result Objects - Detailed status info with user-friendly messages
- 🎨 Adaptive Dialogs - Material (Android) and Cupertino (iOS) dialogs
- ⚡ 40+ Permission Methods - Camera, location, storage, Bluetooth, notifications, and more
- 🔄 Smart Fallbacks - Handles legacy and modern permission APIs
Installation #
Add to your pubspec.yaml:
dependencies:
gt_permission: ^1.1.0
Then run:
flutter pub get
Compatibility & iOS Swift Package Manager (SPM) #
This package is fully compatible with Flutter 3.44.2+ and Dart 3.12.2+.
For iOS, the dependency management utilizes Swift Package Manager (SPM). If you are migrating your iOS app to SPM:
- Ensure your iOS minimum deployment target is set to iOS 15.0 or higher.
- Enable SPM in Flutter:
flutter config --enable-swift-package-manager - Run
flutter build ios --config-onlyto configure the Swift Package Manager setup.
Platform Setup #
Android #
Add permissions to android/app/src/main/AndroidManifest.xml:
<!-- Common permissions -->
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<!-- Add more as needed - see PERMISSION.md for complete list -->
iOS #
Add to ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>We need camera access to take photos</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need photo library access to select photos</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location while using the app</string>
<!-- Add more as needed -->
Under Swift Package Manager, the underlying permission_handler library scans your Info.plist at build time and automatically compiles in only the permissions for which usage descriptions are declared. No manual Podfile modification is required.
Quick Start #
Request Single Permission #
import 'package:gt_permission/gt_permission.dart';
final permissionUtil = PermissionHandlerUtil.instance;
// Request camera permission
final result = await permissionUtil.requestCameraPermission();
if (result.isGranted) {
// Permission granted - open camera
print('Camera access granted!');
} else if (result.isPermanentlyDenied) {
// Show dialog to open settings
await permissionUtil.openAppSettings();
} else {
// Permission denied
print('Denied: ${result.message}');
}
Request Multiple Permissions #
final statuses = await permissionUtil.requestMultiplePermissions([
Permission.camera,
Permission.microphone,
Permission.storage,
]);
bool allGranted = statuses.values.every((s) => s.isGranted);
Check Permission Status #
bool hasCamera = await permissionUtil.isPermissionGranted(Permission.camera);
bool isPermanentlyDenied = await permissionUtil.isPermissionPermanentlyDenied(Permission.location);
Show Platform-Adaptive Dialog #
import 'package:gt_permission/gt_permission.dart';
await PermissionDialogUtils.showResultDialog(
context,
result, // PermissionRequestResult
Permission.camera,
);
Available Permission Methods #
| Method | Description |
|---|---|
requestCameraPermission() |
Camera access |
requestMicrophonePermission() |
Microphone/audio recording |
requestLocationPermission() |
Foreground location |
requestLocationAlwaysPermission() |
Background location |
requestPhotosPermission() |
Photo library (Android 13+: READ_MEDIA_IMAGES) |
requestVideosPermission() |
Video access (Android 13+) |
requestStoragePermission() |
Storage (version-aware) |
requestNotificationPermission() |
Push notifications |
requestBluetoothPermission() |
Bluetooth (version-aware) |
requestContactsPermission() |
Contacts access |
requestCalendarPermission() |
Calendar events |
...and many more! See documentation for complete list.
PermissionRequestResult #
Every request returns a PermissionRequestResult with:
result.isGranted // Permission granted
result.isDenied // Denied but can request again
result.isPermanentlyDenied // Must open settings
result.isLimited // Limited access (iOS 14+ photos)
result.message // User-friendly message
result.shouldOpenSettings // Suggests opening settings
License #
MIT License - see LICENSE for details.