Skip to content

Instantly share code, notes, and snippets.

@alphamikle
Created January 31, 2021 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphamikle/f4693bba070edf0368798df847b6223a to your computer and use it in GitHub Desktop.
Save alphamikle/f4693bba070edf0368798df847b6223a to your computer and use it in GitHub Desktop.
Search in the main thread
Future<void> runSearchOnMainThread() async {
cacheItems();
isLoading = true;
notifyListeners();
searchController.addListener(_searchOnMainThread);
await _testSearch();
searchController.removeListener(_searchOnMainThread);
isLoading = false;
notifyListeners();
}
void _searchOnMainThread() {
final String searchValue = searchController.text;
if (searchValue.isEmpty && items.length != _notFilteredItems.length) {
items.clear();
items.addAll(_notFilteredItems);
notifyListeners();
return;
}
items.clear();
/// Packet2 - wrapper class for two values
items.addAll(filterItems(Packet2(_notFilteredItems, searchValue)));
notifyListeners();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment