search method
searches for the content inside the searchController resets all the other class variables such as items, hasNoMoreItems, and page
Implementation
void search({
bool searchIfEmpty = false,
}) async {
if (query.isEmpty && !searchIfEmpty) {
// if the search is empty, just show them the current items, no need to search
state = PaginatedState.data(items);
return;
}
state = const PaginatedState.loading();
String savedQuery = query;
// debounce search if this function is called within the given timeframe
await Future.delayed(debounceDuration);
if (savedQuery != query) {
// there was another search issued, we will complete the other search and skip this one
debugPrint('debounced search $savedQuery');
return;
}
// resetting the variables for this new search
items.clear();
hasNoMoreItems = false;
page = 1;
_performSearch();
}