Flutter एप्लिकेशन के लिए एक लचीला और शक्तिशाली अनुमति प्रबंधन प्रणाली, जिसमें भूमिका-आधारित पहुंच नियंत्रण, पदानुक्रमिक अनुमतियाँ और कस्टमाइज़ करने योग्य UI घटक हैं।
सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
PermissionPolicy एक शक्तिशाली परमिशन प्रबंधन प्रणाली है, जो Flutter ऐप्स के लिए भूमिका-आधारित एक्सेस नियंत्रण और पदानुक्रमिक परमिशन की अनुमति देती है। यह उपयोगकर्ता एक्सेस को गतिशील रूप से प्रबंधित करने के लिए कस्टमाइज़ किए जा सकने वाले UI घटक प्रदान करता है। सुरक्षा के प्रति सजग ऐप्स के लिए डिज़ाइन किया गया, यह Android, iOS और macOS का समर्थन करता है, जो विकासकर्ताओं को ऐप के भीतर विशिष्ट कार्यों को करने वाले व्यक्तियों को बहुत विस्तृत नियंत्रण प्रदान करता है। पैकेज मौजूदा कार्यप्रवाहों के साथ बिना किसी दिक्कत के एकीकृत होता है और संरचित परमिशन तर्क के माध्यम से ऐप सुरक्षा को बढ़ाता है।
उपयोग
प्रशासक पैनल में उपयोगकर्ता भूमिका प्रबंधन
संवेदनशील विशेषताओं तक पहुँच को नियंत्रित करना
बहु-स्तरीय उपयोगकर्ता पहुँच कार्यान्वयन
बैकएंड API कॉल्स को सुरक्षित करना
एप्लिकेशन स्तर की अनुमतियों का प्रबंधन
रनटाइम पर नीति नियमों के लागू करना
मुख्य विशेषताएँ
भूमिका-आधारित पहुँच नियंत्रण
हायरार्किकल परमिशन संरचना
कस्टमाइज़ेबल यूआई कंपोनेंट्स
प्लेटफॉर्म के लिए समर्थन (Android, iOS, macOS)
डायनामिक परमिशन आकलन
Flutter ऐप्स के साथ आसान एकीकरण
इनके लिए उपयुक्त
एंटरप्राइज-ग्रेड फ्लटर एप्लिकेशन्स
कठोर पहुंच नियंत्रण की आवश्यकता वाले ऐप्स
उपयोगकर्ता भूमिकाओं के साथ प्रशासक डैशबोर्ड
सुरक्षा-केंद्रित मोबाइल ऐप्स
लचीले अनुमति प्रणालियों की आवश्यकता वाले विकासकर्ता
जटिल उपयोगकर्ता पदानुक्रम का प्रबंधन करने वाली टीमें
विचार योग्य बातें
भूमिकाओं और अधिकारों को शुरू में परिभाषित करने की आवश्यकता होती है
कस्टम UI समायोजन की आवश्यकता हो सकती है
अनुमति पदानुक्रम के सही सेटअप पर निर्भर करता है
परिभाषित पहुंच स्तर वाले एप्प्स के लिए सबसे उपयुक्त
डायनामिक नीतियों के लिए अतिरिक्त सेटिंग
सरल एक-उपयोगकर्ता ऐप्स के लिए आदर्श नहीं है
मूल 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: