feat : pagination
This commit is contained in:
@@ -24,6 +24,12 @@ class EnteringTheWarehouseLogic extends GetxController {
|
|||||||
final RxBool addPageImportedLoad = false.obs;
|
final RxBool addPageImportedLoad = false.obs;
|
||||||
final RxBool hasMoreDataImportedLoad = true.obs;
|
final RxBool hasMoreDataImportedLoad = true.obs;
|
||||||
|
|
||||||
|
final ScrollController scrollControllerWaitingForArrival = ScrollController();
|
||||||
|
final RxInt currentPageWaitingForArrival = 1.obs;
|
||||||
|
final RxBool isLoadingMoreWaitingForArrival = false.obs;
|
||||||
|
final RxBool addPageWaitingForArrival = false.obs;
|
||||||
|
final RxBool hasMoreDataWaitingForArrival = true.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onReady() {
|
void onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
@@ -39,6 +45,14 @@ class EnteringTheWarehouseLogic extends GetxController {
|
|||||||
getImportedEntried();
|
getImportedEntried();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scrollControllerWaitingForArrival.addListener(() {
|
||||||
|
if (scrollControllerWaitingForArrival.position.pixels >=
|
||||||
|
scrollControllerWaitingForArrival.position.maxScrollExtent - 100) {
|
||||||
|
addPageWaitingForArrival.value = true;
|
||||||
|
getWaitingArrivals();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getBarGeneralInformation() async {
|
Future<void> getBarGeneralInformation() async {
|
||||||
@@ -59,18 +73,34 @@ class EnteringTheWarehouseLogic extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getWaitingArrivals() async {
|
Future<void> getWaitingArrivals() async {
|
||||||
|
if (isLoadingMoreWaitingForArrival.value ||
|
||||||
|
!hasMoreDataWaitingForArrival.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addPageWaitingForArrival.value) {
|
||||||
|
currentPageWaitingForArrival.value++;
|
||||||
|
}
|
||||||
|
|
||||||
safeCall(
|
safeCall(
|
||||||
call: () async => await rootLogic.chickenRepository.getWaitingArrivals(
|
call: () async => await rootLogic.chickenRepository.getWaitingArrivals(
|
||||||
token: rootLogic.tokenService.accessToken.value!,
|
token: rootLogic.tokenService.accessToken.value!,
|
||||||
page: 1,
|
page: currentPageWaitingForArrival.value,
|
||||||
),
|
),
|
||||||
onError: (error, stackTrace) {
|
onError: (error, stackTrace) {
|
||||||
eLog(error);
|
isLoadingMoreImportedLoad.value = false;
|
||||||
},
|
},
|
||||||
onSuccess: (result) {
|
onSuccess: (result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
waitingForArrival.value = result;
|
waitingForArrival.value = result;
|
||||||
|
if (isLoadingMoreWaitingForArrival.value) {
|
||||||
|
waitingForArrival.value?.results.addAll(result.results);
|
||||||
|
} else {
|
||||||
|
waitingForArrival.value = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isLoadingMoreImportedLoad.value = false;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,8 +298,19 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
|||||||
padding: const EdgeInsets.all(6),
|
padding: const EdgeInsets.all(6),
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
itemCount: data.value?.results.length ?? 0,
|
itemCount: data.value!.results.length+1 ,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
|
||||||
|
if (index == data.value!.results!.length) {
|
||||||
|
return Obx(
|
||||||
|
() => controller.isLoadingMoreWaitingForArrival.value
|
||||||
|
? const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 16),
|
||||||
|
child: Center(child: CircularProgressIndicator()),
|
||||||
|
)
|
||||||
|
: const SizedBox(),
|
||||||
|
);
|
||||||
|
}
|
||||||
final result = data.value!.results[index];
|
final result = data.value!.results[index];
|
||||||
return Card(
|
return Card(
|
||||||
margin: const EdgeInsets.symmetric(vertical: 4.0),
|
margin: const EdgeInsets.symmetric(vertical: 4.0),
|
||||||
|
|||||||
Reference in New Issue
Block a user