I am having trouble displaying user and post data in a listview from the firebase real-time database.
The above three are the images of a real-time database,
From the above, I need to display all posts[tags], and using the host id from the post, I need to display user data along with posts in a listview. But I cannot use two different children of the same reference in the future builder.
How to write the query for the above to display in Flutter listview.
Thanking you in advance.
You have to run two queries in real-time database to get data from two nodes. Either you can create a model class or simply save your data in a Map
.
Note You have to make sure that you already know ID
of the tags (8ux4wwBY03NN2xpM01LXK58rkgF2Tag3947)
in advance to access the hostId
Future<Map<String, dynamic>> future() async {
final tags = await FirebaseDatabase.instance.ref('tags').get();
final data = Map<String, dynamic>.from(tags.value as Map);
final hostID = data['8ux4wwBY03NN2xpM01LXK58rkgF2Tag3947']['hostId'];
final users = await FirebaseDatabase.instance.ref('users/$hostID').get();
return <String, dynamic>{
'tags': Map<String, dynamic>.from(tags.value as Map),
'users': Map<String, dynamic>.from(users.value as Map)
};
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.