I am capturing events from a stream, each event is a Device Object
. The way the stream work is that it is on a timer, so it picks up the same device multiple times and adds to the stream.
I am putting all theres is a List<Device>
and putting that into another stream.
I have create a StreamTransformer
in the attempt to remove duplicate from the list and then add the unique list back into the stream.
This transform code below, I have tried to add to set and back to list, but this hasn't worked I assume due to the fact they are objects not strings.
//Transform Stream List by removing duplicate objects
final deviceList = StreamTransformer<List<Device>, List<Device>>.fromHandlers(
handleData: (list, sink) {
List<Device> distinctList = list.toSet().toList();
sink.add(distinctList);
});
I have attempted to use .where and other libraries but to no avail and am hoping for some guidance.
Device Object contains unique id and name that could be used to filter out duplicates
Question: How can I remove duplicate objects from a List in Dart?
Thanks in advance.