搜索功能不过滤回原始数据

问题描述 投票:0回答:2

如果我们在搜索栏中搜索任何文本……我们会得到过滤后的搜索结果……但问题是所有其他待办事项都消失了..

我无法返回所有其他待办事项..

搜索功能代码

  List<Todos> todList =[];
searchTodo(String enterdText) {
    final search = todList.where((txt) {
      final inputtext = txt.todoText.toLowerCase();
      final input = enterdText.toLowerCase();
      return inputtext.contains(input);
    }).toList();
    setState(() => {todList = search});
  }

搜索栏

TextField(
              onChanged: searchTodo,
              decoration: InputDecoration(
                  hintText: 'Search',
                  prefixIcon: Icon(Icons.search_rounded),
                  //  enabledBorder: InputBorder.none,
                  iconColor: Colors.grey.shade400,
                  border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(20))),
            ),
flutter list dart search
2个回答
0
投票

将列表保存到不同的变量,搜索结束后替换为保存的列表。


0
投票
Something like this... little bit confuse on list size if not replace with length

List<Todos> todList =[];
List<Todos> tmpList =[];
searchTodo(String enterdText){
If(tmpList.size<todList.size){

tmpList=todList;
}
if(enterdText.trim().isEmpty()){
final search=tmpList;


}else{
final search = todList.where((txt) {
  final inputtext = txt.todoText.toLowerCase();
  final input = enterdText.toLowerCase();
  return inputtext.contains(input);
}).toList();}
setState(() => {
If(tmpList.size<todList.size){

tmpList=todList;
}

todList = search});
}
© www.soinside.com 2019 - 2024. All rights reserved.