简体   繁体   English

如何使用 flutter 打印 firebase 文档参考屏幕

[英]How to print firebase document reference to screen using flutter

I would like to know how to print a Firebase document reference to phone7tablet screen using flutter I have tried this so far:我想知道如何使用 flutter 打印 Firebase 文档参考 phone7tablet 屏幕到目前为止我已经尝试过:

StreamBuilder<QuerySnapshot>(stream: stations,builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> snapshot){
                  if(snapshot.hasError){
                    return SnackBar(content: Text("Something went wrong"));
                  }
                  if(snapshot.connectionState == ConnectionState.waiting){
                    return SnackBar(content: Text("Loading"));
                  }
                  final data = snapshot.requireData;

                  return ListView.builder(
                    itemCount: data.size,
                    itemBuilder: (context, index){
                      var ref = data.docs[index]["ref"].toString();
                      return Text(ref);

                    },

Heres a screenshot of my database :这是我的数据库的屏幕截图 数据库截图

To be more elaborate I want to print contents of the document that is being linked by "ref" variable.更详细地说,我想打印由“ref”变量链接的文档的内容。

inside the test collection there are two fields:在测试集合中有两个字段:

  1. name (a string field)名称(字符串字段)
  2. age (an integer field)年龄(integer 字段)

Heres my code output:这是我的代码 output:

在此处输入图像描述

Your ref field seems to be a reference to another document.您的ref字段似乎是对另一个文档的引用。 The linked document is not automatically loaded, but instead returned as a DocumentReference object .链接的文档不会自动加载,而是作为DocumentReference object返回。

To load the linked document, wrap it in a FutureBuilder and call data.docs[index]["ref"].get() as the future, as shown in the FlutterFire documentation onreading a document once .要加载链接的文档,请将其包装在FutureBuilder中并调用data.docs[index]["ref"].get()作为未来,如 FlutterFire 文档 onreading a document once中所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Z047B10EEE763AFB6164E077CF1CC268Z 将文档子集合与文档 JSON map 一起使用 Z035489FF8D0924748149 - How can I pass the document sub-collections along with the document JSON map in Flutter using Firebase? 如何从 flutter 中的 firebase 访问文档 ID? - How to access document ID from firebase in flutter? 使用 fromMap 在 flutter 中映射来自 firebase 文档的嵌套对象 - Mapping nested objects from firebase document in flutter using fromMap 如何使用docx4j将漂亮的JSON打印到Word文档中? - How to print pretty JSON using docx4j into a word document? 如何使用flutter将复杂的JSON数据存储到firebase实时数据库中 - How to store complex JSON data into the firebase realtime database using flutter 如何使用golang打印json文档中“ org”下当前字段中存储的所有元素? - How to print all the elements stored in the field current under “org” in json document in using golang? 如何从json文档中打印列表 - how to print a list from json document 如何使用 firebase 快照打印多个 json 对象数据 - 数据拉取成功 - How can i print multiple json object data using firebase snapshot - data pull succeded 如何使用 Java 在屏幕上打印 JSON 文件的值? - How to print a value of a JSON file on the screen with Java? 如何在 flutter 中将 Json 数据传递到多屏 - How to pass Json data to multi screen in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM