I have a list lets's say 'ProductList'
I have a filter bar with tiltes 'Color' and 'Shape' with toggle buttons Red, green, square and round.
Color: Red Green
Shape: Square Round
1st category - Color
If I click red, the 'ProductList' must be filtered for Red color.
firstFilteredList = ProductList.where((p) => p.color == "red");
Now if I click green, the 'ProductList' must be filtered for Red and Green color.
firstFilteredList = ProductList.where((p) => p.color == "red" || p.color == "green");
2st category - Shape
Now if I click square, the 'firstFilteredList' must be filtered for square shape.
secondFilteredList = firstFilteredList.where((p) => p.shape == "square");
Now if I click round, the 'firstFilteredList' must be filtered for square and round shape.
secondFilteredList = firstFilteredList.where((p) => p.shape == "square" || p.shape == "round");
I need to remove those filters if the button is toggled off.
I've just mentioned two filter categories - Color and shape, for the sake of simplicity. There may be 6-7 filter categories. So, the solution has to be scalable.
Can someone help me solve this?
Edit: ProductList is a element of CategorizedProduct. I have to return List.
class CategorizedProduct {
String id;
String title;
List<Product> product;
String selectedVariant;
}
class Product {
String color;
String id;
bool shapeRectangle;
bool shapeRound;
bool shapeSquare;
}