|
|
|
@@ -26,30 +26,33 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { |
|
|
|
var response; |
|
|
|
if (event.cropId != null) { |
|
|
|
response = await repository.getPlotDetail(event.cropId ?? -1, page: 0, size: pageSize); |
|
|
|
yield PlotDetailSuccess(items: response.activities, page: 0, hasReachedMax: response.activities.length < pageSize ? true : false); |
|
|
|
yield PlotDetailSuccess(items: response.activities, page: 0, hasReachedMax: true); |
|
|
|
} else { |
|
|
|
CropPlot response = await repository.getPlotDetailByCode(event.cropCode ?? ''); |
|
|
|
|
|
|
|
yield PlotDetailSuccess(ownerItem: response, items: response.activities, page: 0, hasReachedMax: true); |
|
|
|
} |
|
|
|
//remove paging |
|
|
|
return; |
|
|
|
} |
|
|
|
if (state is PlotDetailSuccess) { |
|
|
|
final currentState = state as PlotDetailSuccess; |
|
|
|
int page = (currentState.page ?? 0) + 1; |
|
|
|
var response; |
|
|
|
if (event.cropId != null) { |
|
|
|
response = await repository.getPlotDetail(event.cropId ?? -1, page: page, size: pageSize); |
|
|
|
yield response.activities.isEmpty |
|
|
|
? currentState.copyWith(hasReachedMax: true) |
|
|
|
: PlotDetailSuccess( |
|
|
|
items: (currentState.items ?? []) + response.activities, |
|
|
|
page: (currentState.page ?? 0) + 1, |
|
|
|
hasReachedMax: false, |
|
|
|
); |
|
|
|
} else { |
|
|
|
CropPlot response = await repository.getPlotDetailByCode(event.cropCode ?? ''); |
|
|
|
yield PlotDetailSuccess(ownerItem: response, items: response.activities, page: 0, hasReachedMax: true); |
|
|
|
} |
|
|
|
//remove paging |
|
|
|
// final currentState = state as PlotDetailSuccess; |
|
|
|
// int page = (currentState.page ?? 0) + 1; |
|
|
|
// var response; |
|
|
|
// if (event.cropId != null) { |
|
|
|
// response = await repository.getPlotDetail(event.cropId ?? -1, page: page, size: pageSize); |
|
|
|
// yield response.activities.isEmpty |
|
|
|
// ? currentState.copyWith(hasReachedMax: true) |
|
|
|
// : PlotDetailSuccess( |
|
|
|
// items: (currentState.items ?? []) + response.activities, |
|
|
|
// page: (currentState.page ?? 0) + 1, |
|
|
|
// hasReachedMax: false, |
|
|
|
// ); |
|
|
|
// } else { |
|
|
|
// CropPlot response = await repository.getPlotDetailByCode(event.cropCode ?? ''); |
|
|
|
// yield PlotDetailSuccess(ownerItem: response, items: response.activities, page: 0, hasReachedMax: true); |
|
|
|
// } |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
var errorString = AppException.handleError(e); |
|
|
|
@@ -81,7 +84,7 @@ class PlotDetailBloc extends Bloc<PlotDetailEvent, PlotDetailState> { |
|
|
|
response = await repository.getPlotDetailByCode(event.cropCode ?? ''); |
|
|
|
} |
|
|
|
|
|
|
|
yield PlotDetailSuccess(items: response.activities, page: 0, hasReachedMax: response.activities.length < pageSize ? true : false); |
|
|
|
yield PlotDetailSuccess(items: response.activities, page: 0, hasReachedMax: true); |
|
|
|
} catch (e) { |
|
|
|
yield PlotDetailFailure(errorString: AppException.handleError(e)); |
|
|
|
} |