搜索插件、代码仓与 APP 分类

插件详情v5.0.1

easy_permission_validator

PermissonHandler 是一个用于管理 Android 和 iOS 权限的包,通过此包您可以轻松使用 PermissonHandler 库。

AndroidiOSWindows
近 30 天下载
129
喜欢数
36
Pub 分数
150

安装插件

flutter pub add easy_permission_validator

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Easy Permission Validator 是一个 Flutter 包,可简化 Android 和 iOS 上的权限管理,提供一个简单的接口来处理运行时权限。它封装了 PermissionHandler 库,使开发者能够用最少的代码请求、检查和管理应用权限。该包支持相机、位置和存储等常见权限,确保跨平台行为一致。它还提供清晰的权限状态反馈,并处理拒绝或受限访问等边缘情况。非常适合需要用户同意才能使用敏感功能的应用。

适合场景

  • 在照片应用中请求相机访问权限
  • 在使用地图之前检查位置权限
  • 管理文件上传的存储访问
  • 处理跨平台应用中的运行时权限
  • 确保符合隐私法规

主要特点

  • 用于权限检查的简单 API
  • 支持 Android 和 iOS
  • 处理权限状态
  • 内置错误处理
  • 跨平台一致性

适合对象

  • 需要运行时权限的移动应用
  • 寻求快速权限集成的开发者
  • 同时针对 Android 和 iOS 的应用
  • 注重用户隐私的项目
  • 希望减少样板代码的团队

使用建议

  • 某些权限需要原生配置
  • 仅限基本权限类型
  • 可能需要为 Windows 进行额外设置
  • 依赖于底层的 PermissionHandler 库
  • 不支持自定义权限组

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Easy Permission Validator

This package is useful when you need to manage on-demand permissions for both Android and iOS.

pub package

Usage

To use this plugin, add easy_permission_validator as a dependency in your pubspec.yaml file.

Base use:

_permissionRequest() async {
  final permissionValidator = EasyPermissionValidator(
    context: context,
    appName: 'Easy Permission Validator',
  );
  var result = await permissionValidator.camera();
  if (result) {
    // Do something;
  }
}

You can add custom messages for other languages:

_permissionRequest() async {
  final permissionValidator = EasyPermissionValidator(
    context: context,
    appName: 'Easy Permission Validator',
    appNameColor: Colors.red,
    cancelText: 'Cancelar',
    enableLocationMessage:
        'Debe habilitar los permisos necesarios para utilizar la acción.',
    goToSettingsText: 'Ir a Configuraciones',
    permissionSettingsMessage:
        'Necesita habilitar los permisos necesarios para que la aplicación funcione correctamente',
  );
  var result = await permissionValidator.camera();
  if (result) {
    // Do something;
  }
}

In addition, you can add a custom Dialog:

_permissionWithCustomPopup() async {
  final permissionValidator = EasyPermissionValidator(
    context: context,
    appName: 'Easy Permission Validator',
    customDialog: MyAmazingCustomPopup(),
  );
  var result = await permissionValidator.camera();
  if (result) {
    // Do something;
  }
}

Caution

Some permissions must be in the privacy policy

Permissions

If you use any permissions from this package, you must add:

For iOS (add in ios/Runner/Info.plist):

  <!-- Permission options for the `location` group -->
  <key>NSLocationWhenInUseUsageDescription</key>
  <string>Need location when in use</string>
  <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
  <string>Always and when in use!</string>
  <key>NSLocationUsageDescription</key>
  <string>Older devices need location.</string>
  <key>NSLocationAlwaysUsageDescription</key>
  <string>Can I have location always?</string>

  <!-- Permission options for the `mediaLibrary` group -->
  <key>NSAppleMusicUsageDescription</key>
  <string>Music!</string>
  <key>kTCCServiceMediaLibrary</key>
  <string>media</string>

  <!-- Permission options for the `calendar` group -->
  <key>NSCalendarsUsageDescription</key>
  <string>Calendars</string>
  <key>NSCalendarsFullAccessUsageDescription</key>
  <string>Calendar full access</string>

  <!-- Permission options for the `camera` group -->
  <key>NSCameraUsageDescription</key>
  <string>camera</string>

  <!-- Permission options for the `contacts` group -->
  <key>NSContactsUsageDescription</key>
  <string>contacts</string>

  <!-- Permission options for the `microphone` group -->
  <key>NSMicrophoneUsageDescription</key>
  <string>microphone</string>

  <!-- Permission options for the `speech` group -->
  <key>NSSpeechRecognitionUsageDescription</key>
  <string>speech</string>

  <!-- Permission options for the `sensors` group -->
  <key>NSMotionUsageDescription</key>
  <string>motion</string>

  <!-- Permission options for the `photos` group -->
  <key>NSPhotoLibraryUsageDescription</key>
  <string>photos</string>

  <!-- Permission options for the `reminder` group -->
  <key>NSRemindersUsageDescription</key>
  <string>reminders</string>

  <!-- Permission options for the `bluetooth` -->
  <key>NSBluetoothAlwaysUsageDescription</key>
  <string>bluetooth</string>
  <key>NSBluetoothPeripheralUsageDescription</key>
  <string>bluetooth</string>

  <!-- Permission options for the `appTrackingTransparency` -->
  <key>NSUserTrackingUsageDescription</key>
  <string>appTrackingTransparency</string>

  <!-- Permission options for the `assistant` group -->
  <key>NSSiriUsageDescription</key>
  <string>The example app would like access to Siri Kit to demonstrate requesting authorization.</string>

For ANDROID (add in android/app/src/main/AndroidManifest.xml):

Permissions on Android

  <!--
  Internet permissions do not affect the `permission_handler` plugin, but are required if your app needs access to
  the internet.
  -->
  <uses-permission android:name="android.permission.INTERNET"/>

  <!-- Permissions options for the `contacts` group -->
  <uses-permission android:name="android.permission.READ_CONTACTS"/>
  <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
  <uses-permission android:name="android.permission.GET_ACCOUNTS"/>

  <!-- Permissions options for the `storage` group -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <!-- Read storage permission for Android 12 and lower -->
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <!--
    Granular media permissions for Android 13 and newer.
    See https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions
    for more information.
  -->
  <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
  <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
  <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

  <!-- Permissions options for the `camera` group -->
  <uses-permission android:name="android.permission.CAMERA"/>

  <!-- Permissions options for the `sms` group -->
  <uses-permission android:name="android.permission.SEND_SMS"/>
  <uses-permission android:name="android.permission.RECEIVE_SMS"/>
  <uses-permission android:name="android.permission.READ_SMS"/>
  <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH"/>
  <uses-permission android:name="android.permission.RECEIVE_MMS"/>

  <!-- Permissions options for the `phone` group -->
  <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  <uses-permission android:name="android.permission.CALL_PHONE"/>
  <uses-permission android:name="android.permission.ADD_VOICEMAIL"/>
  <uses-permission android:name="android.permission.USE_SIP"/>
  <uses-permission android:name="android.permission.READ_CALL_LOG"/>
  <uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
  <uses-permission android:name="android.permission.BIND_CALL_REDIRECTION_SERVICE"/>

  <!-- Permissions options for the `calendar` group -->
  <uses-permission android:name="android.permission.READ_CALENDAR" />
  <uses-permission android:name="android.permission.WRITE_CALENDAR" />

  <!-- Permissions options for the `location` group -->
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

  <!-- Permissions options for the `microphone` or `speech` group -->
  <uses-permission android:name="android.permission.RECORD_AUDIO" />

  <!-- Permissions options for the `sensors` group -->
  <uses-permission android:name="android.permission.BODY_SENSORS" />
  <uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND" />

  <!-- Permissions options for the `accessMediaLocation` group -->
  <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

  <!-- Permissions options for the `activityRecognition` group -->
  <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

  <!-- Permissions options for the `ignoreBatteryOptimizations` group -->
  <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

  <!-- Permissions options for the `nearby devices` group -->
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />

  <!-- Permissions options for the `manage external storage` group -->
  <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

  <!-- Permissions options for the `system alert windows` group -->
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

  <!-- Permissions options for the `request install packages` group -->
  <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

  <!-- Permissions options for the `access notification policy` group -->
  <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>

  <!-- Permissions options for the `notification` group -->
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

  <!-- Permissions options for the `alarm` group -->
  <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

Issues

Please file any issues, bugs or feature request as an issue on our GitHub page.

Contributions

You can contribute by making a pull request, this package was made for the community and you have complete power to add whatever they find useful.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。