【问题标题】:Firebase: use multiple child in DatabaseReferenceFirebase:在 DatabaseReference 中使用多个孩子
【发布时间】:2021-09-25 23:18:51
【问题描述】:

我需要多次查询 FirebaseDatabase.instance.reference() 中的字段是 .child()

例如,我希望它像这样工作:

         final _itemRef2 = FirebaseDatabase.instance
         .reference()
         .child('lists')
         .child('-Mdso4T8PFejXPXjVhpW','-MdshmYfuEeZWK_hNwZe','-Mdsi6vSVHAmRbxoELNm')
         .child('items');

当然不行啊???

我不明白如何使用 .child 中的值列表?我应该使用什么解决方案?

然后,我想像这样在 FirebaseAnimatedList 中使用 _itemRef2:

          Flexible(
           child: FirebaseAnimatedList(
             query: _itemRef2,
               itemBuilder: (BuildContext context,
                             DataSnapshot snapshot,
                             Animation<double> animation,
                             int index) {
                             return ListTile(

【问题讨论】:

  • 你好 WestDay,你能用图片分享代码吗?

标签: android firebase flutter firebase-realtime-database data-sharing


【解决方案1】:

您不能以这种方式在child 中传递多个值。您必须为每个节点发出单独的请求

final databaseReference = FirebaseDatabase.instance.reference().child("lists");
     
databaseReference.child("list_id_1").once(),
databaseReference.child("list_id_2").once()

您可以尝试使用Future.wait() 同时运行所有Futures。

【讨论】:

  • 好的。以及如何在FirebaseAnimatedList()中正确使用?
  • @WestDay 您有什么具体的查询吗?就像这 3 个列表中是否有任何共同财产?然后你可以在这种情况下使用.equalTo。否则 this answer 解释在 FirebaseAnimatedList 中使用 FutureBuilder。
猜你喜欢
  • 2021-03-11
  • 1970-01-01
  • 2018-01-28
  • 1970-01-01
  • 2017-04-14
  • 1970-01-01
  • 1970-01-01
  • 2018-09-01
  • 1970-01-01
相关资源
最近更新 更多