Created
January 31, 2021 13:58
-
-
Save alphamikle/f4693bba070edf0368798df847b6223a to your computer and use it in GitHub Desktop.
Search in the main thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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