PermissionPolicy는 Flutter 앱을 위한 강력한 권한 관리 시스템으로, 역할 기반 접근 제어 및 계층적 권한을 지원합니다. 사용자 액세스를 동적으로 관리할 수 있는 사용자 정의 가능한 UI 컴포넌트를 제공합니다. 보안에 신경 쓰는 애플리케이션을 위해 설계되었으며 Android, iOS, macOS를 지원하여 개발자가 앱 내 특정 작업을 수행할 수 있는 사용자를 세밀하게 제어할 수 있도록 합니다. 기존 워크플로우와 원활하게 통합되며 구조화된 권한 로직을 통해 앱 보안을 강화합니다.
사용 사례
관리자 패널에서 사용자 역할 관리
민감한 기능에 대한 액세스 제어
다중 계층 사용자 액세스 구현
백엔드 API 호출 보호
앱 수준 권한 관리
런타임 시 정책 규칙 강제 적용
주요 기능
역할 기반 접근 제어
계층적 권한 구조
사용자 정의 가능한 UI 구성 요소
크로스 플랫폼 지원 (Android, iOS, macOS)
동적 권한 평가
Flutter 앱과의 간편한 통합
적합한 대상
기업용 플러터 애플리케이션
엄격한 접근 제어가 필요한 앱
사용자 역할이 있는 관리 대시보드
보안 중심 모바일 앱
유연한 권한 시스템이 필요한 개발자
복잡한 사용자 계층을 관리하는 팀
고려 사항
사전에 역할과 권한을 정의해야 합니다
사용자 정의 UI 조정이 필요할 수 있습니다
권한 계층 구조의 올바른 설정에 달려 있음
정의된 액세스 레벨을 가진 앱에 가장 적합
동적 정책을 위한 추가 구성
간단한 1명 사용자 앱에는 적합하지 않음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Permission Policy for Flutter
A powerful and flexible permission management system for Flutter applications with device-level role-based access control (RBAC), hierarchical permissions, and customizable UI components.
Features
Type-safe models - Permission and Role with full serialization support
Hierarchical permissions - Permissions can inherit from other permissions
Role inheritance - Roles can inherit permissions from other roles
Device-level roles - Assign roles directly to the device — no user identity required
Detailed results - PermissionResult includes the reason, contributing roles, and permissions
Pluggable storage - Implement PermissionStorage for any backend (default uses Nylo local storage)
Performance caching - Resolved permissions are cached and automatically invalidated on changes
UI components - PermissionGuard, PermissionBuilder, and RoleSelector
A Permission represents a specific action or access right. Permissions can inherit from other permissions using inheritsFrom - granting a permission automatically includes its parents.
A Role groups permissions together and can inherit from other roles. Use isAssignable to control whether a role appears in selectors, and isSystem to mark roles that shouldn't be deleted.
Permissions are resolved purely through roles. The device has a list of role IDs, and the system resolves all permissions by walking the role and permission inheritance chains.
API Reference
Checking Permissions
final policy = PermissionPolicy.instance;
// Simple boolean checkbool canEdit = await policy.hasPermission('edit_posts');
// Check any of multiple permissionsbool canManage = await policy.hasAnyPermission(['edit_posts', 'delete_posts']);
// Check all permissions are grantedbool fullAccess = await policy.hasAllPermissions(['read_posts', 'write_posts', 'delete_posts']);
Detailed Permission Results
Use checkPermission to get a PermissionResult with the reason and contributing factors:
PermissionResult result = await policy.checkPermission('edit_posts');
print(result.granted); // true or falseprint(result.reason); // e.g. 'Permission granted through roles'print(result.contributingRoles); // e.g. ['editor']print(result.contributingPermissions); // e.g. ['edit_posts']// Also available for multiple checksPermissionResult anyResult = await policy.checkAnyPermission(['edit_posts', 'delete_posts']);
PermissionResult allResult = await policy.checkAllPermissions(['read_posts', 'write_posts']);
Managing Roles
// Give a role to the deviceawait policy.giveRole('editor');
// Remove a roleawait policy.removeRole('editor');
// Check rolesbool isAdmin = await policy.hasRole('admin');
bool hasEditAccess = await policy.hasAnyRole(['editor', 'admin']);
bool isSuperMod = await policy.hasAllRoles(['moderator', 'admin']);
// Get the device's rolesList<String> roleIds = await policy.getDeviceRoles();
// Get all available rolesList<Role> allRoles = await policy.getRoles();
// Get only assignable roles (isAssignable == true)List<Role> assignable = await policy.getAssignableRoles();
// Get all resolved permissions for the deviceSet<String> allPermissions = await policy.getDevicePermissions();
// Clear all device rolesawait policy.clearRoles();
// Clear everything (permissions, roles, and device roles)await policy.clearAll();
Widgets
PermissionGuard
Conditionally renders a widget based on permissions or roles. Shows the child when granted and the fallback when denied.
RoleSelectorStyle supports customizing spacing, selectedColor, backgroundColor, titleStyle, subtitleStyle, scrollPhysics, and for cards: crossAxisCount and childAspectRatio.
Advanced Usage
Permission Inheritance
Build hierarchical permission structures where higher-level permissions automatically include lower-level ones: