I convert my two list dynamic to an object and I am trying to figure it out how can I check if one of the attribute has the same value example id.
List list1 = [{"id": 2, "name": "test1"}, {"id": 3, "name": "test3"} ];
List list2 = [{"id": 2, "name": "test1"} ];
Here's how I convert it to List object
var list1Protection = GeneralProtectionListModel.fromJson(list1);
var list2Protection = GeneralProtectionListModel.fromJson(list2);
class GeneralProtectionListModel{
final List<GeneralProtectionModel> general;
GeneralProtectionListModel({this.general});
factory GeneralProtectionListModel.fromJson(List<dynamic> json){
List<GeneralProtectionModel> general = new List<GeneralProtectionModel>();
general = json.map((i) => GeneralProtectionModel.fromJson(i)).toList();
return GeneralProtectionListModel(
general: general
);
}
}
class GeneralProtectionModel{
final int id;
final String name;
GeneralProtectionModel({this.id, this.name});
factory GeneralProtectionModel.fromJson(Map<String, dynamic> json){
return GeneralProtectionModel(
id: json['id'],
name: json['name']
);
}
}
I don't have any problem on conversion the List dynamic to List GeneralProtectionListModel
after that I am trying to use the 'where' and 'contains' but it throws me an error says that
The method 'contains' isn't defined for the class 'GeneralProtectionListModel'.
The method 'where' isn't defined for the class 'GeneralProtectionListModel'
list1Protection.where((item) => list2Protection.contains(item.id));