i am making a post app where user like and dislikes post,
and i have added functionality to view who has liked the post
in my post model i have used List for likedby field.
i am passing an string array to function for fetching user details..
this is my first attempt but not getting data
Future<List<UserModel>> fetchUserWhoLiked(List<String> ids) async
{
final snapshot=await FirebaseFirestore.instance.collection('Users').where('Uid',whereIn: list).get();
return snapshot.docs.map((e) => UserModel.fromJson(e)).toList();
}
than i changed to basic level code which returns proper result but not happy with basic level coding
Future<List<UserModel>> fetchUserWhoLiked(List<String> ids) async
{
final List<UserModel> users=[];
for(var id in ids)
{
final snapshot=await FirebaseFirestore.instance.collection('Users').doc(id).get();
users.add(UserModel.fromJson(snapshot));
}
return users;
}
and another thing is what if there is no field of uid in collection and want to fetch by documentId of collection..