I am having trouble figuring out how to Filter a large list twice and display the results in a ListBuilder. Can someone please tell me the best way to go about do this? Here are the details.
First is an example of the data. I would like to first Filter the list by matching the Product Code which is index /element 12. Then I would like to filter the results from the first search to those items that only have a ‘N’ in the first 11 elements IF the user selected that they don’t want that particular feature of the item. Then display the results in a list.
So, in other words. Filter first by a product category code number 1-12 and second by the product characteristics Y or N. Then display each of the items in a List.
It sounded easy when I started but either I’m missing something or I just don’t get it. I did have items displaying the search results but they were not matching the search criteria. Now, I have it all messed up so I’m really just looking to understand the best approach for doing this. So, the user first picks their Category and then on the next screen selects the characteristics to exclude from the final results.
Here is an example of the data.
”’
class CatIngBrain {
final List<CatIng> catIngBank = [
CatIng( "N", "Y", "Y", "Y", "Y", "Y",
"Y", "Y", "Y", "Y","Y", "Y", "1", ‘MAYNARD’, ‘’, ''),
CatIng( "N", "Y", "N", "N", "Y", "N",
"Y", "N", "N", "N","Y", "N", "2", ‘BLESSED EVENT’, '', ‘’, ),
CatIng( "N", "Y", "Y", "Y", "N", "N",
"Y","N", "N", "N", "Y", "N", "3", "GLOBE", '', ''),
The Constructor is setup to match the fields since it is not in Key:Value pairs like alot of the examples I see.
class CatIng {
String ingAcr; //0
String ingBen; //1
String ingCar; //2
String ingFor; //3
String ingFra; //4
String ingPab; //5
String ingPar; //6
String ingPet; //7
String ingPht; //8
String ingSil; //9
String ingSul; //10
String ingTol; //11
String ingCatCode; //12
String prodName; //13
CatIng(
this.ingAcr, //0
this.ingBen,//1
this.ingCar,//2
this.ingFor,//3
this.ingFra,//4
this.ingPab,//5
this.ingPar,//6
this.ingPet,//7
this.ingPht,//8
this.ingSil,//9
this.ingSul,//10
this.ingTol,//11
”’
Edit, just focusing on the first filter, which I think is my problem:
The Filter I am using on the above for the Product Category is
''' final Iterable<dynamic> ingsToFilterList =
catIngBrain.catIngBank.where((e) => e.ingCatCode ==
passedIngCatCode).toList();'''
This is just to filter the Category. It returns [Instance of ‘CatIng’, Instance of ‘CatIng’] but when I display the return in the list, it does not display the correct index for the two index items that do contain the correct category code.
Thanks for any suggestions
2
Answers
I was able to get the Product Category to search correctly by using this: '''' ''' final ingsToFilterList = catIngBrain.catIngBank.where((catIngs) => catIngs.ingCatCode == passedIngCatCode).toList();
Unfortunately, I have not been able to get the next filter level to work yet.
U can check this sort