[英]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:在测试集合中有两个字段:
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.