I would like to implement a filter in flutter and change dynamically the ListView based on the items that comply with the filters. I have a list of peoples (represented by the class People with attribute AGE in it). For instance I would like to show people with age < 18, but WITHOUTH REMOVING the items from the list generating the list view, just HIDE the items from the ListView that do not comply with the filter.
CodePudding user response:
You only need to put a condition for rendering the list, and show the person only if he/she is < 18. you can do something like this in your listview:
ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
if (person.age < 18)
return Text(person.age);
return Text('');
},
)
CodePudding user response:
Using Visibility Class from flutter sdk we can hide/show as we need