Source enum
Configures the behavior of DocumentReference.get and Query.get. By providing a Source value, these methods can be configured to fetch results only from the server, only from the local cache, or attempt to fetch results from the server and fall back to the cache (which is the default).
This replaces the separate getDocFromCache / getDocFromServer functions of the JS SDK.
// Only the server; fails with FirestoreErrorCode.unavailable when offline.
final DocumentSnapshot<Map<String, Object?>> fresh = await firestore
.doc('cities/SF')
.get(const GetOptions(source: Source.server));
// Only the cache; never contacts the backend.
final QuerySnapshot<Map<String, Object?>> cached = await firestore
.collection('cities')
.get(const GetOptions(source: Source.cache));
Values
- serverAndCache → const Source
-
Causes Firestore to try to retrieve an up-to-date (server-retrieved) snapshot, but fall back to returning cached data if the server can't be reached: the default of DocumentReference.get and Query.get.
- server → const Source
-
Causes Firestore to avoid the cache, generating an error (
FirestoreErrorCode.unavailable) if the server cannot be reached. Note that the cache will still be updated if the server request succeeds. Also note that latency-compensation still takes effect, so any pending write operations will be visible in the returned data (merged into the server-provided data). - cache → const Source
-
Causes Firestore to immediately return a value from the cache, ignoring the server completely (implying that the returned value may be stale with respect to the value on the server). If there is no data in the cache to satisfy the
getcall, DocumentReference.get fails withFirestoreErrorCode.unavailableand Query.get returns a QuerySnapshot with the documents the cache has, possibly none. A document that the cache knows to be missing gives a snapshot whoseexistsis false.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- index → int
-
A numeric identifier for the enumerated value.
no setterinherited
- name → String
-
Available on Enum, provided by the EnumName extension
The name of the enum value.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.
inherited