Reputation: 3
I have a json list of 3 eligibilities. From where i have to filter id and store it to another list, the json list as widget.eligibility is below
[{id: 13, category_id: 9, title: Must be over the age of 18 to assist, details: Must be over the age of 18 to assist, status: 1, created_at: 2022-08-06T10:26:59.000000Z, updated_at: 2022-08-06T10:26:59.000000Z, pivot: {opportunity_id: 15, eligibility_id: 13}}, {id: 14, category_id: 9, title: Must be a female, details: Must be a female, status: 1, created_at: 2022-08-06T10:27:17.000000Z, updated_at: 2022-08-06T10:27:17.000000Z, pivot: {opportunity_id: 15, eligibility_id: 14}}, {id: 15, category_id: 9, title: Must be able to lift my wheelchair/20 kg, details: Must be able to lift my wheelchair/20 kg, status: 1, created_at: 2022-08-06T10:27:32.000000Z, updated_at: 2022-08-06T10:27:32.000000Z, pivot: {opportunity_id: 15, eligibility_id: 15}}]
my code
List<int> eligibility = [];
setState(() {
eligibility = (widget.eligibility.where((element) => element.id)).toList();
});
print(eligibility);
Upvotes: 0
Views: 328
Reputation: 86
.add() Function are use to insert value in a list
your code should be like this
List<int> eligibility = [];
for(Map map in widget.eligibility){ // where the widget.eligibility is came from previous widget which seems a list of map in your code
eligibility.add(map['id']);
}
setState((){}); // set state after creating a list
Upvotes: 1