feat: autorefresh
Build Android APK (split per ABI) / build-apk (push) Waiting to run
Build & Deploy iOS to TestFlight / build-and-deploy (push) Waiting to run

This commit is contained in:
efrilm
2026-10-27 17:51:26 +07:00
parent e7c77051ab
commit a2f3af27b1
6 changed files with 102 additions and 11 deletions
@@ -12,6 +12,11 @@ part 'order_loader_bloc.freezed.dart';
@injectable
class OrderLoaderBloc extends Bloc<OrderLoaderEvent, OrderLoaderState> {
final IOrderRepository _repository;
int _fetchRequestId = 0;
int _summaryRequestId = 0;
bool _isLoadingMore = false;
OrderLoaderBloc(this._repository) : super(OrderLoaderState.initial()) {
on<OrderLoaderEvent>(_onOrderLoaderEvent);
}
@@ -34,19 +39,43 @@ class OrderLoaderBloc extends Bloc<OrderLoaderEvent, OrderLoaderState> {
emit(state.copyWith(outletId: e.outletId));
},
fetched: (e) async {
var newState = state;
if (e.isRefresh) {
newState = state.copyWith(isFetching: true);
emit(newState);
_fetchRequestId++;
emit(state.copyWith(isFetching: true));
} else if (state.isFetching || _isLoadingMore) {
return;
}
newState = await _mapFetchedToState(state, isRefresh: e.isRefresh);
final requestId = _fetchRequestId;
_isLoadingMore = !e.isRefresh;
emit(newState);
try {
final result = await _mapFetchedToState(
state,
isRefresh: e.isRefresh,
);
// Filter berubah selama request berjalan, buang hasil lama
if (requestId != _fetchRequestId) return;
// Hanya ambil field list, supaya status/filter/summary terbaru
// tidak tertimpa snapshot lama
emit(
state.copyWith(
orders: result.orders,
failureOptionOrder: result.failureOptionOrder,
page: result.page,
hasReachedMax: result.hasReachedMax,
isFetching: false,
),
);
} finally {
if (!e.isRefresh) _isLoadingMore = false;
}
},
summaryFetched: (e) async {
final requestId = ++_summaryRequestId;
emit(state.copyWith(isFetchingSummary: true));
final results = await Future.wait([
@@ -63,6 +92,8 @@ class OrderLoaderBloc extends Bloc<OrderLoaderEvent, OrderLoaderState> {
),
]);
if (requestId != _summaryRequestId) return;
emit(
state.copyWith(
isFetchingSummary: false,