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

插件详情v1.0.0+1

permission_asker

permission_handler 的包装器,可减少我们在应用程序中处理权限所需的大量样板代码。

AndroidiOS
近 30 天下载
4
喜欢数
19
Pub 分数
130

安装插件

flutter pub add permission_asker

插件介绍

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

Permission_Asker 是一个 Flutter 包,通过封装 permission_handler 库来简化权限处理。它减少了在 Android 和 iOS 应用中请求和管理权限所需的样板代码,提供更简洁、更清晰的 API。该包简化了常见的权限工作流程,使检查、请求和响应权限状态变得更加容易,而无需重复编写代码。非常适合希望使用轻量级解决方案来提高处理设备权限时代码可读性和可维护性的开发者。

适合场景

  • 在照片应用中请求相机访问权限
  • 在导航应用中处理位置权限
  • 管理文件上传的存储访问
  • 在录制前检查麦克风权限
  • 简化跨多个屏幕的权限检查

主要特点

  • 通过简洁的 API 减少样板代码
  • 无缝包装 permission_handler
  • 支持 Android 和 iOS 平台
  • 提供便捷的权限状态检查
  • 提供直观的请求方法

适合对象

  • 使用 permission_handler 的开发者
  • 需要频繁管理权限的应用程序
  • 注重代码清晰、可读性的团队
  • 旨在减少重复权限逻辑的项目
  • Flutter 初学者学习权限处理

使用建议

  • 需要 permission_handler 作为依赖项
  • 仅限基本权限操作
  • 无内置的UI自定义
  • 不处理复杂的权限流程
  • 取决于底层 permission_handler 的行为

原始 README

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

permission_asker

A wrapper for permission_handler which lifts some of the boilerplate needed to handle permissions in our apps.

Why

Usually, when we need to build our widgets according to the permission status of a certain feature we need to check if the permission is granted or not and ask for it. Since these are async operations we usually need to add some boilerplate to do the right thing at the right time.

What

In addition to everything that's provided with permission_handler by exposing it, this package provides:

  • a PermissionAsker class which allows to ask permissions and react to the results via the onPermissionData callback.
  • a PermissionAskerBuilderclass which allows to build a widget according to the status of a list of permissions

Setup

Check here for setting up your permissions.

Usage

Here's an example on how you can use the PermissionAskerBuilder widget

PermissionAskerBuilder(
  permissions: [
      Permission.location,
      Permission.camera,
  ],
  grantedBuilder: (context) => Center(
      child: Text('All permissions granted!'),
  ),
  notGrantedBuilder: (context, notGrantedPermissions) => Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
            Text('Not granted permissions:'),
            for (final p in notGrantedPermissions) 
              Text(p.toString())
        ],
      ),
  ),
  notGrantedListener: (notGrantedPermissions) => print('Not granted:\n$notGrantedPermissions'),
)

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。