done method
Change the state to done
if not, then append the items to the result.
This will be called when fetcher
finished. And the next state depends on the result of fetcher
.
DO NOT call this method directly, trigger it by performing a search action.
Implementation
@protected
void done(Iterable<T>? items) {
if (_state is SearchStatusLoading<T>) {
if (items?.isNotEmpty != true) {
_state = SearchStatusIdle();
} else {
_state = SearchStatusDone(items!.toList());
}
} else if (_state is SearchStatusLoadingMore<T>) {
_state = SearchStatusDone((_state as SearchStatusLoadingMore<T>).result);
if (items?.isNotEmpty == true) {
(_state as SearchStatusDone).result.addAll(items!);
}
} else {
throw StateError('Unexpected transition');
}
notifyListeners();
}