List a = [
AbsentModel(name: "abir", id: 1),
AbsentModel(name: "fahim", id: 2),
AbsentModel(name: "rahim", id: 3),
AbsentModel(name: "akash", id: 4), ]
List b = [
AbsentModel(name: "akash", id: 4),
AbsentModel(name: "fahim", id: 2),
AbsentModel(name: "rahim", id: 3),]
`
I need the output of –
the difference between List a and List b
result –
`List c = [ AbsentModel(name: "abir", id: 1),];
I have tried to toSet() but it only can give me the result If i made all list without model.
Like if made simple id List then it works.
But can not get the difference when I am using model data.
2
Answers
This code would work fine as others. You just need to use equatable package.
However, you need to redefine the
AbsentModel
as follows:The first answer is correct, but does not take into account the fact that the deviating value would not be recognised if it were in list b.
This solution is similar to the above one, but checks the difference from
a
tob
and fromb
toa
. Also it is written as an extension for genericList
, so it can be used for all kind of lists.Also you do not have to use the Equatable package (if you don’t want to), since you could overload the
==
operator: