updateState method
void
updateState(
- State update
Updates current state
state - new state value
Listeners of stream will be notified about changes
Future<void> loadPosts(int offset, int limit, {bool refresh = false}) async {
updateState(state.copyWith(posts: LoadingData()));
late Response<List<Post>> response;
if (refresh) {
response = await Apis.posts.getPosts(0, limit).execute();
} else {
response = await Apis.posts.getPosts(offset, limit).execute();
}
if (response.isSuccessful || response.isSuccessfulFromDatabase) {
updateState(state.copyWith(posts: SuccessData(response.result ?? [])));
} else {
updateState(state.copyWith(posts: ErrorData(response.error)));
}
}
Implementation
void updateState(State update) {
if (_isDisposed) {
throw IllegalStateException(
message: 'Can\'t call updateState after dispose.',
);
}
_state.update(update);
}