【问题标题】:How can I filter the content of listview when clicked a button?单击按钮时如何过滤列表视图的内容?
【发布时间】:2021-10-06 13:53:26
【问题描述】:

我还没有使用 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];”一开始,我会得到过滤后的值。但点击按钮时不会改变

【问题讨论】:

    标签: android flutter dart listview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-27
      • 2013-01-13
      • 1970-01-01
      • 2014-10-08
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多