A flexible and powerful permission management system for Flutter applications with role-based access control, hierarchical permissions, and customizable UI components.
Package selection guidance compiled from public package information, community data, and project usage.
PermissionPolicy is a robust permission management system for Flutter apps, enabling role-based access control and hierarchical permissions. It provides customizable UI components to manage user access dynamically. Designed for security-conscious applications, it supports Android, iOS, and macOS, offering developers fine-grained control over who can perform specific actions within the app. The package integrates seamlessly with existing workflows and enhances app security through structured permission logic.
Use cases
User role management in admin panels
Controlling access to sensitive features
Implementing multi-tier user access
Securing backend API calls
Managing app-level permissions
Enforcing policy rules at runtime
Key features
Role-based access control
Hierarchical permission structure
Customizable UI components
Cross-platform support (Android, iOS, macOS)
Dynamic permission evaluation
Easy integration with Flutter apps
Suitable for
Enterprise-grade Flutter applications
Apps requiring strict access controls
Admin dashboards with user roles
Security-focused mobile apps
Developers needing flexible permission systems
Teams managing complex user hierarchies
Considerations
Requires defining roles and permissions upfront
May need custom UI adjustments
Depends on proper setup of permission hierarchy
Best suited for apps with defined access levels
Additional configuration for dynamic policies
Not ideal for simple one-user apps
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
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: