BaseEntity class abstract

The base contract for all entities used with blocx.

Every BaseEntity must expose a unique, constant identifier. This identifier is the sole basis for equality and hashCode comparisons, meaning two entities of the same type are considered equal if they share the same identifier.

Identifier requirements:

  • Must be unique within its entity type.
  • Must be constant/stable across the entity’s lifecycle.
  • Common choices:
    • Remote UUIDs
    • Database primary keys (stringified if needed)
    • Usernames / emails (if immutable in your domain)

Example:

class User extends BaseEntity {
  final String id;
  final String name;

  @override
  String get identifier => id;

  const User({required this.id, required this.name});
}

final u1 = User(id: "abc123", name: "Alice");
final u2 = User(id: "abc123", name: "Alice Updated");

// Even though the `name` differs, equality is based only on `id`.
assert(u1 == u2);
Implementers

Constructors

BaseEntity()
const

Properties

hashCode int
The hash code for this object.
no setteroverride
identifier String
A globally unique and constant identifier for the entity.
no setter
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.
inherited

Operators

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