User class final

Core application user model.

A User represents an authenticated or auth-capable account within the framework. It stores identity fields, an optional hashed password, and exposes convenience helpers for loading attached roles.

Example:

final user = User(
  name: 'Jane Doe',
  email: 'jane@example.com',
  password: 'secret123',
);

print(user.email); // jane@example.com
Inheritance
Mixed-in types
Available extensions

Constructors

User({required String name, required String email, String? password})
Creates a new user instance.
User.fromJson(Map<String, dynamic> json)
Creates a user model from a JSON map.

Properties

createdAt DateTime?
Creation timestamp (UTC).
getter/setter pairinherited
disk DatabaseDisk
getter/setter pairinherited
email String
User email address.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
id int?
Primary key (auto-incremented by backend).
getter/setter pairinherited
name String
User display name.
getter/setter pair
password String?
Hashed password value, when present.
getter/setter pair
roles Future<List<Role>>
Resolves all roles attached to this user through the user/role pivot table.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
updatedAt DateTime?
Last update timestamp (UTC).
getter/setter pairinherited
uuid String?
UUID for cross-backend identification.
getter/setter pairinherited

Methods

attach(Model sibling, {required ModelRelationshipType relationship, PivotTable<Model, Model>? table, DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on Model, provided by the ModelRelationshipOps extension

Attaches sibling to this model using the given relationship type.
attachRole(RoleType role, {DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on User, provided by the HasRole extension

Attaches the given role to the user.
belongsToMany<T extends Model>({required PivotTable<Model, Model> table, DatabaseDisk disk = Model.defaultDisk}) Future<List<T>>

Available on Model, provided by the ModelRelationships extension

Resolves many-to-many related models through a pivot table.
belongsToOne<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<T?>

Available on Model, provided by the ModelRelationships extension

Resolves the parent model for an inverse relationship.
delete({DatabaseDisk? disk}) Future<bool>
Deletes the current instance.
inherited
detach(Model sibling, {required ModelRelationshipType relationship, PivotTable<Model, Model>? table, DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on Model, provided by the ModelRelationshipOps extension

Detaches sibling from this model using the given relationship type.
detachRole(RoleType role, {DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on User, provided by the HasRole extension

Detaches the given role from the user.
getInstanceTableName() String
inherited
getInstanceTableSingularName() String
inherited
hasMany<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<List<T>>

Available on Model, provided by the ModelRelationships extension

Resolves all one-to-many related models.
hasOne<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<T?>

Available on Model, provided by the ModelRelationships extension

Resolves a one-to-one related model.
hasRole(RoleType role) Future<bool>

Available on User, provided by the HasRole extension

Returns true when the user currently has the given role.
load<T extends Model>(ModelRelationshipType relationship, {PivotTable<Model, Model>? table}) Future<Map<String, dynamic>>

Available on Model, provided by the ModelRelationshipOps extension

Loads a relationship and returns this model serialized with the related data embedded.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save({DatabaseDisk? disk}) Future<bool>
Saves the current instance.
inherited
toJson() Map<String, dynamic>
Serializes the user into its standard JSON representation.
override
toMetaJson() Map<String, dynamic>
Serializes the user into a metadata-oriented JSON map.
override
toString() String
Human-readable string representation.
inherited
update({required Map<String, dynamic> withJson, DatabaseDisk? disk}) Future<bool>
Updates the current instance with new data.
inherited
withRoles() Future<Map<String, dynamic>>
Returns this user serialized with resolved role data.
withRoles() Future<Map<String, dynamic>>

Available on User, provided by the HasRole extension

Returns this user serialized with resolved role data.

Operators

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

Static Properties

columnDefinitions Map<String, String>
Database column definitions for persisted users.
getter/setter pair