feat : pagination
This commit is contained in:
@@ -24,6 +24,12 @@ class EnteringTheWarehouseLogic extends GetxController {
|
||||
final RxBool addPageImportedLoad = false.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
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
@@ -39,6 +45,14 @@ class EnteringTheWarehouseLogic extends GetxController {
|
||||
getImportedEntried();
|
||||
}
|
||||
});
|
||||
|
||||
scrollControllerWaitingForArrival.addListener(() {
|
||||
if (scrollControllerWaitingForArrival.position.pixels >=
|
||||
scrollControllerWaitingForArrival.position.maxScrollExtent - 100) {
|
||||
addPageWaitingForArrival.value = true;
|
||||
getWaitingArrivals();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getBarGeneralInformation() async {
|
||||
@@ -59,18 +73,34 @@ class EnteringTheWarehouseLogic extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> getWaitingArrivals() async {
|
||||
if (isLoadingMoreWaitingForArrival.value ||
|
||||
!hasMoreDataWaitingForArrival.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (addPageWaitingForArrival.value) {
|
||||
currentPageWaitingForArrival.value++;
|
||||
}
|
||||
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.getWaitingArrivals(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
page: 1,
|
||||
page: currentPageWaitingForArrival.value,
|
||||
),
|
||||
onError: (error, stackTrace) {
|
||||
eLog(error);
|
||||
isLoadingMoreImportedLoad.value = false;
|
||||
},
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
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),
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
itemCount: data.value?.results.length ?? 0,
|
||||
itemCount: data.value!.results.length+1 ,
|
||||
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];
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
|
||||
Reference in New Issue
Block a user