ServerTimestampBehavior enum

Controls the return value for server timestamps that have not yet been set to their final value.

A field written with FieldValue.serverTimestamp has no value on the client until the server has applied the write. Until then a snapshot with pending writes reads it according to this behavior. Pass it to DocumentSnapshot.getData, get, getField, getTimestamp or getDate; data uses none.

final DocumentReference<Map<String, Object?>> post = firestore.doc('posts/a');
final Future<void> written = post.set(<String, Object?>{
  'createdAt': FieldValue.serverTimestamp(),
});
final DocumentSnapshot<Map<String, Object?>> local = await post.get(
  const GetOptions(source: Source.cache),
);
local.get('createdAt'); // null
local.get(
  'createdAt',
  serverTimestamps: ServerTimestampBehavior.estimate,
); // now
await written;

This is the JS SDK's serverTimestamps snapshot option ('none', 'estimate', 'previous').

Inheritance
Available extensions

Values

none → const ServerTimestampBehavior

Return 'null' for FieldValue.serverTimestamp values that have not yet been set to their final value.

estimate → const ServerTimestampBehavior

Return local estimates for FieldValue.serverTimestamp values that have not yet been set to their final value. This estimate will likely differ from the final value and may cause these pending values to change once the server result becomes available.

The estimate is the time of the local write, read from this device's clock.

previous → const ServerTimestampBehavior

Return the previous value for FieldValue.serverTimestamp values that have not yet been set to their final value.

If the field had no value before the write, it is read as null.

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

Constants

values → const List<ServerTimestampBehavior>
A constant List of the values in this enum, in order of their declaration.