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

@@ -574,7 +574,7 @@ class Repository {
// Crop
Future<List<TbCropDTO>> crops({
int page = 0,
int size = 20,
int size = 1000,
required CropFilterRequest filter,
}) async {
try {

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

@@ -39,23 +39,23 @@ class PlotBloc extends Bloc<PlotEvent, PlotState> {
if (state is PlotInitial) {
yield PlotLoading();
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) {
var errorString = AppException.handleError(e);
yield PlotFailure(errorString: errorString);
@@ -65,7 +65,7 @@ class PlotBloc extends Bloc<PlotEvent, PlotState> {
try {
yield PlotLoading();
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) {
yield PlotFailure(errorString: AppException.handleError(e));
}
@@ -73,7 +73,7 @@ class PlotBloc extends Bloc<PlotEvent, PlotState> {
try {
yield PlotLoading();
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) {
yield PlotFailure(errorString: AppException.handleError(e));
}

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

@@ -24,7 +24,11 @@ class PlotSuccess<T> extends PlotState {
const PlotSuccess({this.items, this.page, this.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

Loading…
Cancel
Save