Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firestore Server side Timestamp

I need to add a server side timestamp on new documents added to Firestore using a Flutter app. I see I am supposed to use FieldValue.serverTimestamp but I am not sure where to find this.

like image 632
spongyboss Avatar asked Jun 18 '18 10:06

spongyboss


People also ask

How do I read firestore timestamp in flutter?

Inside the map you should find the timestamp under the corresponding field name, e.g. documentSnapshot. data['FIELD_NAME_HERE'] .

How do I use FieldValue serverTimestamp in flutter?

serverTimestamp() to a timestamp on the client. What you can do is write FieldValue. serverTimestamp() to a document on the server, and observe the value that is written to that document. This value will be a valid timestamp.

What is FieldValue in firebase?

The FieldValue sentinel for use in a call to set() or update() . public static FieldValue increment (long l) Returns a special value that can be used with set() or update() that tells the server to increment the field's current value by the given value.


2 Answers

As of September 5th, the updated cloud_firestore v0.8.0 library now has FieldValue.serverTimestamp(). All is now well in the universe

like image 152
spongyboss Avatar answered Oct 09 '22 02:10

spongyboss


'timestamp' : Timestamp.now()

Timestamp.now() is part of cloud_firestore;


Example enter image description here Screenshot showing that the library is imported from cloud_firestore, and creates a server-generated timestamp in the written data. Docs

like image 20
John Ravi Avatar answered Oct 09 '22 02:10

John Ravi