簡體   English   中英

如何在顫動中像這種格式一樣將數據寫入firebase

[英]How to write data to firebase like this format in flutter

如何像這種格式將數據寫入firebase?

在此處輸入圖像描述

qHFij7jKyTa1t9RhkWN2LImqwVl2是用戶 ID, -MjYl_8EVJJkWcHgn6mJ是帖子 ID,

我嘗試使用此代碼

await _firestore
            .collection('Notifications')
            .doc(FirebaseAuth.instance.currentUser!.uid)
            .collection(postid)
            .doc()
            .set({
          'userid': FirebaseAuth.instance.currentUser!.uid,
          'comment': 'test',
          'postid': postid,
          'ispost': true,
          'time': DateTime.now(),
        });

在此處輸入圖像描述

但這不是我想要的。

在我在 Android 的舊項目中,代碼是

ref = ref.getInstance.getReference("Notifications").child(publisherid);
HashMap<String, Object> hashmap = new HashMap<>();
hashmap.put("userid", userid);
hashmap.put("comment", comment);
hashmap.put("postid", postid);
hashmap.put("ispost", true);
hashmap.put("time", DateTime.now());

這種格式怎么能行?

在此處輸入圖像描述

您可以通過以下方式輕松創建子集合。

CollectionReference notifications = FirebaseFirestore.instance.collection('Notifications');

notifications.doc('qHFij7jKyTa1t9RhkWN2LImqwVl2').collection('MjYl_8EVJJkWcHgn6mJ').add({
            'comment': 'liked your post',
            'isPost': 'true', 
          });

FirebaseFirestore.instance.collection('通知')

.doc('qHFij7jKyTa1t9RhkWN2LImqwVl2').collection('MjYl_8EVJJkWcHgn6mJ')

.add({ 'comment': '喜歡你的帖子', 'isPost': 'true', });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM