init method
- {bool showLoading = true}
Handle a remote call and emit the appropriate state
Implementation
void init({bool showLoading = true}) async {
if (showLoading) safeEmit(const PaginatedCleanState.loading());
final response = await remoteCall(initialPage).run();
safeEmit(response.match(
errorHandler,
(paginatedResponse) {
updatePagination(paginatedResponse);
return successHandler.call(paginatedResponse);
},
));
/// complete the completer only if the loading is not shown
/// this is to prevent the refresh indicator being shown for a split second
/// when the data is already available
/// we only want to show the refresh indicator only when showLoading is false
if (!showLoading) complete();
}