Firebase:在 DatabaseReference 中使用多个孩子

问题描述

我需要多次查询 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(

解决方法

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

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

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