从Flutter中的Firestore查询单个文档(cloud_firestore插件)

从Flutter中的Firestore查询单个文档(cloud_firestore插件),第1张

从Flutter中的Firestore查询单个文档(cloud_firestore插件)

但这似乎不是正确的语法

这是不正确的语法,因为您错过了

collection()
通话。您无法
document()
直接致电
Firestore.instance
。要解决此问题,您应该使用以下方法:

var document = await Firestore.instance.collection('COLLECTION_NAME').document('TESTID1');document.get() => then(function(document) {    print(document("name"));});

或者以更简单的方式:

var document = await Firestore.instance.document('COLLECTION_NAME/TESTID1');document.get() => then(function(document) {    print(document("name"));});

如果要实时获取数据,请使用以下代码:

Widget build(BuildContext context) {  return new StreamBuilder(      stream: Firestore.instance.collection('COLLECTION_NAME').document('TESTID1').snapshots(),      builder: (context, snapshot) {        if (!snapshot.hasData) {          return new Text("Loading");        }        var userdocument = snapshot.data;        return new Text(userdocument["name"]);      }  );}

它还将帮助您将名称设置为文本视图



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4979843.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-14
下一篇2022-11-14

发表评论

登录后才能评论

评论列表(0条)

    保存