List 列表的复杂排序

List 列表的复杂排序,list,flutter,dart,List,Flutter,Dart,我有两张单子 列表1包含一个对象。该对象的一个方面是个人ID[1,2,3,4,5],列表2包含符合条件[1,3,5]的个人ID 我需要筛选列表1以仅显示满足条件的对象 比如: var sortedList = list1 .where((item) => item.personID == "Any of the ids contained within list2) .toList(); 因此sortedList=id 1,3,5的对象简短回答

我有两张单子

列表1包含一个对象。该对象的一个方面是个人ID[1,2,3,4,5],列表2包含符合条件[1,3,5]的个人ID

我需要筛选列表1以仅显示满足条件的对象

比如:

 var sortedList = list1
          .where((item) => item.personID == "Any of the ids contained within list2)
          .toList();

因此sortedList=id 1,3,5的对象

简短回答

Iterable filteredList=list.where((元素){
返回列表2
.map((元素)=>元素personId)
托利斯先生()
.contains(element.personId);
});
你可以看看这个飞镖运动场

完整脚本

类项目{
int personId;
项目({this.personId});
字符串toString(){
返回“$personId”;
}
}
列表=[
项目(人名:1),
项目(人名:2),
项目(人名:3),
项目(人名:4),
项目(人名:5),
];
列表2=[
项目(人名:1),
项目(人名:3),
项目(人名:5),
];
void runFunction(){
Iterable filteredList=列表,其中((元素){
返回列表2
.map((元素)=>元素personId)
托利斯先生()
.contains(element.personId);
});
列表结果=filteredList.toList();
打印(结果);
}
main(){
runFunction();
}