TurboWriteable class abstract
A base class for objects that can be written to Firestore.
This abstract class provides the foundation for objects that need to be stored in Firestore. It enforces validation and serialization requirements through two key methods:
- validate for ensuring data integrity before writing
- toJson for converting the object to a Firestore-compatible format
Example:
class User extends TurboWriteable {
User({required this.name, required this.age});
final String name;
final int age;
@override
TurboResponse<void>? validate<void>() {
if (name.isEmpty) {
return TurboResponse.fail(message: 'Name cannot be empty');
}
if (age < 0) {
return TurboResponse.fail(message: 'Age cannot be negative');
}
return null;
}
@override
Map<String, dynamic> toJson() => {
'name': name,
'age': age,
};
}
- Implementers
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- 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.
-
toString(
) → String -
A string representation of this object.
inherited
-
validate<
T> () → TurboResponse< T> ? - Validates the object's data before writing to Firestore.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited