I have two lists, one with posted images and a second with friends. Only friends posts should be displayed from the posts list. In this case for Obi.
class postModel{
String? image;
String? userId;
String? name;
int? age;
postModel({this.image, this.userId, this.name, this.age});
}
List<postModel> imageList = [
postModel(image: "imageUrl", userId: "1gw3t2s", name: "Luke", age: 21),
postModel(image: "imageUrl2", userId: "hjerhew", name: "Joda", age: 108),
postModel(image: "imageUrl3", userId: "475fdhr", name: "Obi", age: 30),
postModel(image: "imageUrl4", userId: "jrt54he", name: "Vader", age: 35),];
class friendModel{
String? userId;
String? name;
friendModel({this.userId, this.name});
}
List<friendModel> friendList = [
friendModel(userId: "1gw3t2s", name: "Luke"),
friendModel(userId: "hjerhew", name: "Joda"),];
//...
ListView.builder(
itemCount: imageList.length,
itemBuilder: (context, i) {
return friendList.contains(imageList[i].userId) //something like that
?Image.network(imageList[i].image)
:Container();
}
Output should be only the post from Luke and Joda
thanks