How to display a list of data from a map ? - flutter firestore
221
You should try something like that:
var userDocument = snapshot.data;
final List<Widget> children = [];
userDocument['bookedEvents'].forEach((key, value) {
children.add(Text(value['eventName'])); });
return Column(children: children); // or Row(children: children); or ListView(children: children);
Author by
Haritha Madhushanka
Updated on December 28, 2022Comments
-
Haritha Madhushanka over 1 year
I am building an event management app. When the user buys a ticket, the ticket details are being saved in the DB like this.
Users -> (Current User ID) -> (map)bookedEvents -> eventId -> [event details]
I managed to display data of one specific event when I give one of the Event IDs as a static String like this.
StreamBuilder( stream: FirebaseFirestore.instance .collection('users') .doc(_uid) .snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) { return Text("Loading"); } var userDocument = snapshot.data; return Text( userDocument["bookedEvents"]["KFXvCj63y7GTjQcMKfVy"] ["eventName"], style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20), ); }),
But I want to display all the Event Names in a list. Could I know how? Thank you so much.