firebase - flutter 和 Firebase : How can I put the documentID into the document field the moment I just create the document?

标签 firebase flutter dart google-cloud-firestore

Flutter & Firebase:如何在创建文档时将 documentID 放入文档字段?

通常情况下,如果我们创建文档时没有指定documentID,firebase会为我们生成一个ID,对吧?

就我而言,我希望 firebase 为我生成 ID,然后将该 ID 放入文档字段之一。我该怎么做?

await feedbackCollection.document().setData({
      'comment' : comment,
      'feedback_id' : ????,
    });

最佳答案

DocumentReference docRef = await feedbackCollection.document();
    docRef.setData({
      'comment' : comment,
      'feedback_id' : docRef.id,
    });

关于firebase - flutter 和 Firebase : How can I put the documentID into the document field the moment I just create the document?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64366566/

相关文章:

multithreading - 如何同时启动多个 Future 以填充单个 FutureBuilder ListView?

Dart HttpRequest 轮询

firebase - 有没有办法根据注册 ID 或通知键名称检索现有的通知键?

android - Flutter:不使用 AppBar 时如何在 Android 和 iOS 上更改状态栏文本颜色

json - 如何在Flutter/Dart中创建通用类型的对象?

android - 如何在 Android 10 上添加 FLAG_SECURE - Flutter

java - 在 Android 的 FirestoreRecyclerAdapter 中显示 ServerValue.TIMESTAMP

android - 如何正确嵌套数据并写入Firebase

firebase - 世博会是否支持 Firebase 电话身份验证?

flutter - 使用InheritedWidget在子级中触发触发器 Action