Browse Source

remove paging list plot

phase2_apinhatky
Đại Võ 1 year ago
parent
commit
99afbb458b
3 changed files with 24 additions and 20 deletions
  1. +1
    -1
      lib/data/repository/repository.dart
  2. +18
    -18
      lib/presentation/screens/plot/bloc/plot_bloc.dart
  3. +5
    -1
      lib/presentation/screens/plot/bloc/plot_state.dart

+ 1
- 1
lib/data/repository/repository.dart View File

// Crop // Crop
Future<List<TbCropDTO>> crops({ Future<List<TbCropDTO>> crops({
int page = 0, int page = 0,
int size = 20,
int size = 1000,
required CropFilterRequest filter, required CropFilterRequest filter,
}) async { }) async {
try { try {

+ 18
- 18
lib/presentation/screens/plot/bloc/plot_bloc.dart View File

if (state is PlotInitial) { if (state is PlotInitial) {
yield PlotLoading(); yield PlotLoading();
final response = await getPlots(0); final response = await getPlots(0);
yield PlotSuccess(items: response, page: 0, hasReachedMax: response.length < pageSize ? true : false);
}
if (state is PlotSuccess) {
final currentState = state as PlotSuccess;
if (currentState.hasReachedMax ?? false) {
return;
}
int page = (currentState.page ?? 0) + 1;
final response = await getPlots(page);
yield response.isEmpty
? currentState.copyWith(hasReachedMax: true)
: PlotSuccess(
items: (currentState.items ?? []) + response,
page: (currentState.page ?? 0) + 1,
hasReachedMax: false,
);
yield PlotSuccess(items: response, page: 0, hasReachedMax: true);
} }
// if (state is PlotSuccess) {
// final currentState = state as PlotSuccess;
// if (currentState.hasReachedMax ?? false) {
// return;
// }
// int page = (currentState.page ?? 0) + 1;
// final response = await getPlots(page);
// yield response.isEmpty
// ? currentState.copyWith(hasReachedMax: true)
// : PlotSuccess(
// items: (currentState.items ?? []) + response,
// page: (currentState.page ?? 0) + 1,
// hasReachedMax: false,
// );
// }
} catch (e) { } catch (e) {
var errorString = AppException.handleError(e); var errorString = AppException.handleError(e);
yield PlotFailure(errorString: errorString); yield PlotFailure(errorString: errorString);
try { try {
yield PlotLoading(); yield PlotLoading();
final response = await getPlots(0); final response = await getPlots(0);
yield PlotSuccess(items: response, page: 0, hasReachedMax: response.length < pageSize ? true : false);
yield PlotSuccess(items: response, page: 0, hasReachedMax: true);
} catch (e) { } catch (e) {
yield PlotFailure(errorString: AppException.handleError(e)); yield PlotFailure(errorString: AppException.handleError(e));
} }
try { try {
yield PlotLoading(); yield PlotLoading();
final response = await getPlots(0); final response = await getPlots(0);
yield PlotSuccess(items: response, page: 0, hasReachedMax: response.length < pageSize ? true : false);
yield PlotSuccess(items: response, page: 0, hasReachedMax: true);
} catch (e) { } catch (e) {
yield PlotFailure(errorString: AppException.handleError(e)); yield PlotFailure(errorString: AppException.handleError(e));
} }

+ 5
- 1
lib/presentation/screens/plot/bloc/plot_state.dart View File

const PlotSuccess({this.items, this.page, this.hasReachedMax}); const PlotSuccess({this.items, this.page, this.hasReachedMax});


PlotSuccess copyWith({List<T>? items, int? page, bool? hasReachedMax}) { PlotSuccess copyWith({List<T>? items, int? page, bool? hasReachedMax}) {
return PlotSuccess(items: items ?? this.items, page: page ?? this.page, hasReachedMax: hasReachedMax ?? this.hasReachedMax);
return PlotSuccess(
items: items ?? this.items,
page: page ?? this.page,
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
);
} }


// @override // @override

Loading…
Cancel
Save