Flutter Firestore Server side Timestamp

前端 未结 3 783
借酒劲吻你
借酒劲吻你 2020-12-03 13:22

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 no

3条回答
  •  眼角桃花
    2020-12-03 14:02

    Expanding on @spongyboss' answer (which works as of April 2020) by adding sample usage:

    _firestore.collection('messages').add({
                          'text': messageText,
                          'sender': loggedInUser.email,
                          'created': FieldValue.serverTimestamp()
                      });
    

    'created' will be stored as a timestamp

    Sample sorting:

    _firestore.collection('messages')
              .orderBy('created', descending: false)
              .snapshots()
    

提交回复
热议问题