handleRefresh method
Implementation
void handleRefresh({
required PagedRefreshExecutor<R> executor,
}) async {
final previousItems = state.items;
/// showing is refreshing
emit(state.copyWith(refreshStatus: RefreshStatus.refreshing));
/// This is inner function
Future<QuerySnapshot<R>> fetch() async {
final result = await executor();
return result;
}
try {
/// fetch from zero
final result = await fetch();
final items = result.docs.map((e) {
return FireData(object: e.data(), doc: e);
}).toList();
/// Here we are not appending items we just set new ones.
if (items.isEmpty) {
emit(state.copyWith(
status: PagedStatus.end,
items: [],
refreshStatus: RefreshStatus.success,
));
} else {
emit(state.copyWith(
status: _hasReachedEnd(items.length),
items: items,
refreshStatus: RefreshStatus.success,
));
}
} catch (e) {
/// If there is error we just show previous items
emit(state.copyWith(
items: previousItems,
refreshStatus: RefreshStatus.failure,
message: e.toString(),
));
}
}