我现在想做一个列表搜索,就是本来初始化后有列表10个人,全部显示出来,然后在搜索栏上输入搜索关键字,然后根据搜索结果显示其中的几条,,,但是setState好像只渲染改变的ITEM,其余的ITEM并不会消失,这样就没办法将搜索结果显示出来,其余的几条给删掉.
Widget FinderBox() {
return new Container(
child: Column(
children: <Widget>[
new Container(
width: 500,
height: 40,
color: Colors.grey,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
width: 340,
height: 30,
child: new TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
contentPadding: EdgeInsets.all(10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5),
borderSide: BorderSide.none),
),
onChanged: (text) {
//内容改变的回调
var isFind = SearchResult(text);
print(isFind);
if(isFind != null){
setState(() {
showData = isFind;
});
}
},
autofocus: true,
),
)
],
))
],
),
);
}
SearchResult(String str) {
//查找对比结果
final allContact = lists;
List<ContactInfos> array = [];
for (var value in allContact) {
var result = value.name.indexOf(str);
if (result != -1) {
array.add(value);
return array;
}
}
}
请问各位大佬有什么好的解决方案吗,你们是怎么做搜索结果显示的### 问题描述
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)