|
|
|
|
|
|
|
|
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)); |
|
|
} |
|
|
} |