TurboWriteableId<T extends Object> class
abstract
A base class for Firestore documents that require a unique identifier.
This abstract class extends TurboWriteable and adds functionality for handling document identifiers in Firestore. It provides a type-safe way to work with document IDs and includes functionality to track whether a document is a local default.
Type parameter T
represents the type of the document's ID (typically String).
The ID type must be non-nullable (extends Object).
Example of a basic implementation:
class User extends TurboWriteableId<String> {
User({
required this.name,
this.isDefault = false,
}) : super(isLocalDefault: isDefault);
final String name;
@override
String get id => 'user-123';
@override
Map<String, dynamic> toJson() => {
'name': name,
};
@override
TurboResponse<void>? validate<void>() {
if (name.isEmpty) {
return TurboResponse.fail(message: 'Name cannot be empty');
}
return null;
}
}
Example usage with custom ID type:
class CustomId {
const CustomId(this.value);
final String value;
@override
String toString() => value;
}
class Document extends TurboWriteableId<CustomId> {
Document() : super();
@override
CustomId get id => CustomId('doc-123');
}
- Inheritance
-
- Object
- TurboWriteable
- TurboWriteableId
Constructors
- TurboWriteableId.new({bool isLocalDefault = false})
- Creates a new instance of TurboWriteableId.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → T
-
The unique identifier for this document.
no setter
- isLocalDefault → bool
-
Whether this instance represents a default local value.
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
-
toJson(
) → Map< String, dynamic> -
Converts the object to a Firestore-compatible map.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
validate<
T> () → TurboResponse< T> ? -
Validates the object's data before writing to Firestore.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited