FirestoreEntity<T extends FirestoreEntity<T>> class abstract

This drop-in replacement for Dataclass adds support for common Firestore operations and allows access to the Firestore document ID.

Constructors

FirestoreEntity()

Properties

documentChanges Stream<T?>
Returns a stream of the document changes. This stream will emit the current document immediately, and then emit any changes to the document.
no setter
hashCode int
The hash code for this object.
no setterinherited
id String?
This is the Firestore ID of the document. Will be automatically set when storing a new document, but can also be set manually.
getter/setter pair
isValid bool
Returns true if this object is valid. Does not throw any exceptions if the object is invalid.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selfCollection → CollectionReference<T>
Returns the collection reference of this document.
no setter
selfDocument → DocumentReference<T>
Returns the document reference of this document.
no setter

Methods

$find<R extends FirestoreEntity<R>>({Query<R> query(Query<R> query)?}) Future<R?>
Finds the first R entity in the corresponding subcollection of this entity matching the query. Returns null if no entity was found.
$get<R extends FirestoreEntity<R>>(String id, {R orCreate()?}) Future<R?>
$query<R extends FirestoreEntity<R>>({Query<R> query(Query<R> query)?, R? startAfter, R? endBefore, R? startAt, R? endAt}) Future<List<R>>
Returns all R entities in the corresponding subcollection of this entity matching the query.
$store<R extends FirestoreEntity<R>>(R entity) Future<R?>
Stores an R entity which in the corresponding subcollection of this entity.
delete() Future
Deletes the document from Firestore. If the document does not exist, this method does nothing.
exists() Future<bool>
Checks if the document exists in Firestore.
getSubCollection<R extends FirestoreEntity<R>>() → CollectionReference<R>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
postRebuild(T from, T to) → void
Runs after from has been rebuilt into to;
save() Future<T>
Saves the document to Firestore. If the document does not exist, it will be created. If this document doesn't have an ID yet, a new ID will be generated and instantly updated, you don't have to wait for the Future to complete to get the ID.
snapshot() Future<DocumentSnapshot<Object?>>
Returns a future of the latest snapshot of this document. This is purely for use with queries, and should not be used for anything else.
toString() String
A string representation of this object.
inherited
update(Map<String, dynamic> data) Future<T>
Updates the document in Firestore. If the document does not exist, this method does nothing. Warning: This method takes normal firestore data and does not use converters.
validate() → void
Throws an exception if this object is invalid.
inherited
withParent<R extends FirestoreEntity<R>>(R parent) → T
Sets the parent collection of this document. This is required for subcollections.

Operators

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

Static Methods

find<T extends FirestoreEntity<T>>({Query<T> query(Query<T> query)?}) Future<T?>
get<T extends FirestoreEntity<T>>(String id, {T orCreate()?}) Future<T?>
Gets the document from Firestore. If the document does not exist, this method returns null.
query<T extends FirestoreEntity<T>>({Query<T> query(Query<T> query)?, T? startAfter, T? endBefore, T? startAt, T? endAt}) Future<List<T>>