Role class final

An immutable role that bundles a set of Permissions.

Roles may inherit other roles via inherits, forming a simple hierarchy.

const editorRole = Role(
  id: 'editor',
  name: 'Editor',
  permissions: [Permission.read('posts'), Permission.write('posts')],
);
const adminRole = Role(
  id: 'admin',
  name: 'Admin',
  permissions: [Permission.all('settings')],
  inherits: ['editor'],
);
Annotations

Constructors

Role({required String id, required String name, required List<Permission> permissions, List<String> inherits = const []})
Creates a Role.
const

Properties

hashCode int
The hash code for this object.
no setteroverride
id String
Unique identifier used to reference this role, e.g. 'editor'.
final
inherits List<String>
IDs of roles whose permissions this role inherits.
final
name String
Human-readable display name, e.g. 'Editor'.
final
permissions List<Permission>
Permissions directly granted to this role.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override