我的FireBase结构如下:
android - FirebaseAnimatedList中的嵌套子键查询-LMLPHP
我想在FireBaseAnimatedList中获取“groupname”列表。
如何做到这一点?
我的当前代码:

chatGroupNameReference = FirebaseDatabase.instance.reference().child("chat_group_message_user_info").child(widget.user.uid);


body: new Container(
    child: new Flexible(
      child: new FirebaseAnimatedList(
        query: chatGroupNameReference,
        padding: const EdgeInsets.all(8.0),
        defaultChild: Center(child: CircularProgressIndicator(backgroundColor: Colors.deepPurpleAccent,),),
        itemBuilder: (_, DataSnapshot messageSnapshot,
            Animation<double> animation, int index) {

          return Text("Group Name will be here")
        },
      ),
    )
  )
);

最佳答案

对于嵌套的子键查询,我们需要具有FireBaseAnimatedList的FutureBuilder:

chatGroupNameReference = FirebaseDatabase.instance.reference().child("chat_group_message_user_info").child(widget.user.uid);

body: new FirebaseAnimatedList(
    defaultChild: Center(child: new CircularProgressIndicator()),
    query: chatGroupNameReference,
    sort: (a,b) => (b.key.compareTo(a.key)),
    itemBuilder: (_, DataSnapshot messageSnapshot, Animation<double> animation, int index) {

      return new FutureBuilder<DataSnapshot>(
        future: chatGroupNameReference.child(messageSnapshot.key).once(),
        builder: (BuildContext context, snapshot){

          return snapshot.hasData ? new Text(snapshot.data.value['groupName']) : new Text("");
        },
      );
    },

07-28 01:45