![](/img/trans.png)
[英]Flutter app error - type 'Timestamp' is not a subtype of type 'DateTime'
[英]Error type 'Null' is not a subtype of type 'Timestamp'
我將當前日期設置為 firebase 並嘗試檢索它以用作參考。 但不知何故,結果有所不同。 有時我有一個 null 值,但有時沒關系。 我試圖添加一個延遲命令,但它仍然表現相同。 請幫忙。 謝謝!
//set current date
await db.collection(Paths.playersPath).doc(uid).set({
'currDate': FieldValue.serverTimestamp(),
}, SetOptions(merge: true));
DocumentSnapshot<Map<String, dynamic>> documentSnapshot =
await db.collection(Paths.playersPath).doc(uid).get();
Timestamp currDate = documentSnapshot.data()!['currDate'];
編輯:我不太確定它是否已連接,但我有 2 個調用相同邏輯的方法。 一個在幾乎總是失敗的 HookWidget 下,另一個在 StatefulWidget 下,從來沒有問題。
編輯:我真的不知道為什么。 但是當我將更新當前日期的事件移動到有狀態小部件時,它現在可以工作了。 希望有人能澄清這一點。
你能試試這個嗎:
db.collection(Paths.playersPath).doc(uid).get().then((value) => value.data();['currDate']);
如果仍然無法正常工作,您還可以嘗試使用db.collection(Paths.playersPath).doc(uid).set
進行鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.