FieldValue.serverTimestamp constructor

FieldValue.serverTimestamp()

Sets the field to the time at which the server applies the write.

Until the server confirms the write, a snapshot reads the field as null by default; pass ServerTimestampBehavior.estimate or ServerTimestampBehavior.previous to getData, get or getTimestamp of the snapshot to read a local estimate or the previous value instead. While the client is offline the field stays pending until the write reaches the server.

await firestore.doc('posts/hello').set(<String, Object?>{
  'title': 'Hello',
  'createdAt': FieldValue.serverTimestamp(),
});

Implementation

factory FieldValue.serverTimestamp() => _serverTimestampInstance;