Good morning, a question made me balls when I wanted to do the following I have this structure
Data = [
{"id" : 1, "nombre" : "A", "cantidad" : 20},
{"id" : 1, "nombre" : "A", "cantidad" : 30},
{"id" : 2, "nombre" : "B", "cantidad" : 15},
{"id" : 2, "nombre" : "B", "cantidad" : 10},
{"id" : 3, "nombre" : "C", "cantidad" : 20}]
I want to get this result only from the id's without duplicate
R=[{"id" : 1}, {"id" : 2}, {"id" : 3}]
either
R = [1, 2, 3]
Simple, in the long form:
In the short form:
The trick is to use
toSet()
so that it adds the elements without repeating.More info: https://api.flutter.dev/flutter/dart-core/Set-class.html