Mr. Tacio
Mr. Tacio

Reputation: 562

Timestamp is having a null value when saving in Firebase

I have the following code:

      DocumentReference ref = db.collection(Paths.playersPath).doc(uid);
      var data = {
        'uid': uid,
        'name': name,
        'email': email,
        'joinDate': FieldValue.serverTimestamp(),
      };
      ref.set(data, SetOptions(merge: true));
      final DocumentSnapshot currentDoc = await ref.get();
      user = Player.fromFirestore(currentDoc);

When I save this in firebase, it is having an error:

type 'Null' is not a subtype of type 'Timestamp'

When I show this via print, it shows the following value:

FieldValue(Instance of 'MethodChannelFieldValue')

Please help on what is the issue. Thanks!

Upvotes: 0

Views: 825

Answers (2)

Harsh Dhar Agarwal
Harsh Dhar Agarwal

Reputation: 1

For Kotlin, Timestamp(Date()) in place of FieldValue.serverTimestamp() worked. To use Timestamp(Date()), you must import com.google.firebase.Timestamp. Not sure if things are different for Flutter.

Upvotes: 0

Shaybakov
Shaybakov

Reputation: 756

this article

  1. The listener fires, and you get the existing value of the timestamp. 2.The listener fires again, and you observe null for the createdAt field. 3.The listener fires yet again, and you observe an actual timestamp value.

Upvotes: 2

Related Questions