if we search for any text in the search bar …we get filtered search results... but the issue is that all other To-dos are gone ..
I cant get back to all other Todos ..
search function code
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});
}
search bar
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))),
),
CodePudding user response:
Save your list to a different variable and once the search ends replace with the saved list.
CodePudding user response:
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});
}