我的Firebase结构是这样的:
我想在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")
},
),
)
)
);
答案 0 :(得分:2)
对于嵌套子键查询,我们需要带有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("");
},
);
},
答案 1 :(得分:1)
(_, DataSnapshot messageSnapshot,
Animation<double> animation, int index)
在该行之后,您可以使用FutureBuilder
从Firebase数据库获取数据。