how can i filter list from other list?

Viewed 20

how can i filter and get list of dog in secondData that have type; ['c1'] from list cat from firstData that have id; 'c1'

must type; ['c1'] = id; 'c1'

simple code :

const firstData = [ Cat( id;'c1', title;'man') ];

const secondData = [ dog( id;'m1', type;['c1'], title;'women') ];

1 Answers

I think this will solve your problem

you just need to use where after your list

List<Cat> firstData = [Cat(id: 'c1', title: 'man')].toList();
List<Cat> check(String id) {
return firstData.where((cat) => cat.id==id).toList();
// or 
 return secondData .where((dog) => dog.type==id).toList();
}
Related