I have a field in Firebase that contains values and each value is an id for a user document here
I fetched all the values from the array and stored them inside a variable as shown in the code below:
List<dynamic> ids = [];
Map<String, dynamic>? map;
late DocumentReference<Map<String, dynamic>> doc = databaseService.db.collection(userCollection).doc(auth.chatUser.uid);
Then I tried to insert all the values I got into a loop in order to fetch each member's data using the id's I got as shown :
getIdsWithData() async {
var res = await doc.get();
setState(() {
ids.clear();
ids.add(res.data()!["requests"]);
});
for (var element in ids) {
var data = await databaseService.db.collection(userCollection).doc(element).get();
map = data.data();
}
print(map);}
But when executing the code, I get the error:
Unhandled Exception: type 'List' is not a subtype of type 'String?
I tried to solve by putting (.first) after (ids) and the problem was already solved as shown :
for (var element in ids.first) {
var data = await databaseService.db.collection(userCollection).doc(element).get();
map = data.data();
}
but I face another problem, which is that I want to store these values from the loop to a variable that I use to display the member data in ListTile (listview.builder) as shown :
Widget listView() {
return ListView.separated(
itemCount: map!.length,
separatorBuilder: (BuildContext context, int index) => const Divider(),
itemBuilder: (BuildContext context, int index) {
return CustomListTile(
title: map![index]["name"],
subtitle: map![index]["id"],
image: map![index]["image"],
);
},
);}
Thanks for help