连续从流构建器中检索数据

发布于 2025-01-28 19:49:22 字数 1173 浏览 6 评论 0原文

我正在尝试用云燃烧器实现流构建器来检索现场数据。 这是代码:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("test builder"),
      ),
      body:  StreamBuilder<QuerySnapshot>(
          stream: FirebaseFirestore.instance.collection('joystick').snapshots(),
          builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
            if(!snapshot.hasData){
              return Center(
                child: CircularProgressIndicator(),
              );
            }

              return ListView.builder(
                  itemCount: snapshot.data?.docs.length,
                  itemBuilder: (context, i){

                    QueryDocumentSnapshot<Object?>? ds = snapshot.data?.docs[i];
                    return Text("$snapshot.data?.docs[i].data()!['call']");
                  });


          }
      ),

    );
  }

但是,它不会输出数据库中存储的实际数据。 我将获得以下输出:

AsyncSnapshot<QuerySnapshot<Object?
>>(ConnectionState.active,Instance of '_JsonQuerySnapshot',null, null).data?.docs[i].data()!['call']

如何将数据存储在数据库中? (字段名称为“呼叫”)

I am trying to implement stream builder with cloud firestore to retrieve field data.
Here is the code:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("test builder"),
      ),
      body:  StreamBuilder<QuerySnapshot>(
          stream: FirebaseFirestore.instance.collection('joystick').snapshots(),
          builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
            if(!snapshot.hasData){
              return Center(
                child: CircularProgressIndicator(),
              );
            }

              return ListView.builder(
                  itemCount: snapshot.data?.docs.length,
                  itemBuilder: (context, i){

                    QueryDocumentSnapshot<Object?>? ds = snapshot.data?.docs[i];
                    return Text("$snapshot.data?.docs[i].data()!['call']");
                  });


          }
      ),

    );
  }

However, it does not output the actual data stored in the database.
I get the following output:

AsyncSnapshot<QuerySnapshot<Object?
>>(ConnectionState.active,Instance of '_JsonQuerySnapshot',null, null).data?.docs[i].data()!['call']

What should I do to get the data stored in the database? (The field name is 'call')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阪姬 2025-02-04 19:49:22

为了实现使用Cloud Firestore的流构建器来检索字段数据,您可以按照 noreferrer“> StreamBuilder文档

如前所述, thread ,您可以在通过StreamBuilder检索数据时浏览以下代码:

 正文:新的streambuilder( 
   流:firestore.instance.Collection(“ Collection”)。快照(), 
   建筑商:(上下文,快照){ 
     如果(!snapshot.hasdata){
   返回文本(“无数据...”,); 
} 
别的 { 
&lt; documentsnapshot&gt;项目= snapshot.data.documents; 
返回new Lost_card( 
HeadImageAssetPath:项目[0] [“ url”]); 
}
 

如果您想从许多文档中创建列表构建器,
这个

 返回new ListView.builder( 
itemcount:snapshot.data.documents.length, 
itembuilder :(上下文,索引){ 
documentsnapshot ds = snapshot.data.documents [index]; 
返回new Lost_card( 
HeadImageAssetPath:DS [“ url”]; 
);
 

,您可以参考文档已经解释了使用Cloud Firestore的更新。

In order to implement stream builder with cloud firestore to retrieve field data, you can follow the StreamBuilder Documentation and link related to explanation of streambuilder in flutter.

As mentioned the thread, you can go through the following code on retrieving data through streambuilder :

body: new StreamBuilder( 
   stream: Firestore.instance.collection("collection").snapshots(), 
   builder: (context, snapshot) { 
     if (!snapshot.hasData) {
   return Text( 'No Data...', ); 
} 
else { 
<DocumentSnapshot> items = snapshot.data.documents; 
return new Lost_Card( 
headImageAssetPath : items[0]["url"] ); 
}

If you want to create list builder from many documents use it like
this

return new ListView.builder( 
itemCount: snapshot.data.documents.length, 
itemBuilder: (context, index) { 
DocumentSnapshot ds = snapshot.data.documents[index]; 
return new Lost_Card( 
headImageAssetPath : ds["url"]; 
);

For more information, you can refer to the Documentation where real time updates with cloud firestore have been explained.

亣腦蒛氧 2025-02-04 19:49:22

尝试此一个返回数据

return Text(ds['enterYourDataFieldName']);

Try this one to return your data

return Text(ds['enterYourDataFieldName']);
゛清羽墨安 2025-02-04 19:49:22

您正在尝试实现疑虑的实时数据库,而不是为此而制定Firestore数据库。

What you are trying to achieve concerns RealTime database, Firestore database is not made for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文