LIST 1: I have a list with user ids: (selected users)
['1234', '3455', '2330', '1111']
LIST 2: I have a second list with the full profile of the users (map): (all users)
[{"id": '1234', "name": "username"}, {"id": '3455' .... ]
LIST 3: I would like to have a third list that contains all selected users: returning all users of LIST 2 that have an id of LIST 1.
I tried this...
list1.forEach((element) =>
list3.add(list2.where((data) => data['id'] == element)));
But that doesn't work...
error: The argument type 'Iterable<Map<String, dynamic>>' can't be assigned to the parameter type 'Map<String, dynamic>'.
What am I doing wrong?
Thanks in advance!
You can use list3 = list2.where((map)=>list1.contains(map["id"])).toList()
for create list3
And the reason of issue is your list3 needs a map, but your list2.where(..)
code is returns List[map, map, map]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With