单击按钮时如何过滤列表视图的内容?

How can I filter the content of listview when clicked a button?

我还没有使用 API 或 firebase,数据存储在本地。 这是我的代码 ======>>

Widget _buildhouse(BuildContext contex, int index){
Size size = MediaQuery.of(context).size;

House house = houselist[index];   //houselist is the list of all houses

return GestureDetector(
  onTap: (){
   setState(() {]
     
    house = filteredhouse[index];  //this code wont be executed
   
     print(house.price);
   });
    Navigator.push(context, MaterialPageRoute(builder: (_) => DetailsScreen(house),));
  },

所以我评论的那两行我猜是重要的,打印代码被执行但不是另一行。如果我说“house = filteredhouse[index];”一开始,我会得到过滤后的值。但点击按钮时不会改变

通过使用这个函数解决了它 void _filtered(){ setState(() { houselist = filteredhouse; }); } 然后在 setState

中调用它