feat : pagination

This commit is contained in:
MrM
2025-06-06 18:50:16 +03:30
parent 31792a2f8a
commit 63e9ec585d
7 changed files with 78 additions and 20 deletions

View File

@@ -220,8 +220,5 @@ class ChickenRepositoryImpl implements ChickenRepository {
fromJson: DashboardKillHouseFreeBar.fromJson, fromJson: DashboardKillHouseFreeBar.fromJson,
); );
return res.data; return res.data;
} }
} }

View File

@@ -204,4 +204,10 @@ class EnteringTheWarehouseLogic extends GetxController {
weightLossController.clear(); weightLossController.clear();
authenticationCodeController.clear(); authenticationCodeController.clear();
} }
@override
void dispose() {
rootLogic.inventoryExpandedList.clear();
super.dispose();
}
} }

View File

@@ -58,7 +58,6 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
) )
: ListView.separated( : ListView.separated(
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: controller.rootLogic.inventoryList.length, itemCount: controller.rootLogic.inventoryList.length,
separatorBuilder: (context, index) => separatorBuilder: (context, index) =>
const SizedBox(height: 8), const SizedBox(height: 8),
@@ -297,10 +296,10 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
height: 700, height: 700,
padding: const EdgeInsets.all(6), padding: const EdgeInsets.all(6),
child: ListView.separated( child: ListView.separated(
controller: controller.scrollControllerWaitingForArrival,
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
itemCount: data.value!.results.length+1 , itemCount: data.value!.results.length + 1,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
if (index == data.value!.results!.length) { if (index == data.value!.results!.length) {
return Obx( return Obx(
() => controller.isLoadingMoreWaitingForArrival.value () => controller.isLoadingMoreWaitingForArrival.value

View File

@@ -33,7 +33,6 @@ class RootLogic extends GetxController {
getKillHouseDistributionInfo(); getKillHouseDistributionInfo();
} }
void toggleExpanded(int index) { void toggleExpanded(int index) {
if (inventoryExpandedList.keys.contains(index)) { if (inventoryExpandedList.keys.contains(index)) {
inventoryExpandedList.remove(index); inventoryExpandedList.remove(index);
@@ -86,15 +85,14 @@ class RootLogic extends GetxController {
); );
} }
void _handleGeneric(DioException error) { void _handleGeneric(DioException error) {
Get.showSnackbar( Get.showSnackbar(
_errorSnackBar('اعتبار توکن شما منقضی شده است لطفا دوباره وارد شوید' _errorSnackBar('اعتبار توکن شما منقضی شده است لطفا دوباره وارد شوید'),
),
); );
tokenService.deleteTokens(); tokenService.deleteTokens();
Get.offAllNamed(AuthPaths.auth, arguments: Module.chicken ); Get.offAllNamed(AuthPaths.auth, arguments: Module.chicken);
} }
GetSnackBar _errorSnackBar(String message) { GetSnackBar _errorSnackBar(String message) {
return GetSnackBar( return GetSnackBar(
titleText: Text( titleText: Text(

View File

@@ -138,4 +138,10 @@ class SalesWithOutProvinceLogic extends GetxController {
}*/ }*/
Future<void> submitAllocation() async {} Future<void> submitAllocation() async {}
@override
void dispose() {
rootLogic.inventoryExpandedList.clear();
super.dispose();
}
} }

View File

@@ -28,6 +28,12 @@ class SalesWithinProvinceLogic extends GetxController {
final pricePerKiloController = TextEditingController(); final pricePerKiloController = TextEditingController();
final totalCostController = TextEditingController(); final totalCostController = TextEditingController();
final ScrollController scrollControllerAllocationsMade = ScrollController();
final RxInt currentPageAllocationsMade = 1.obs;
final RxBool isLoadingMoreAllocationsMade = false.obs;
final RxBool addPageAllocationsMade = false.obs;
final RxBool hasMoreDataAllocationsMade = true.obs;
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
@@ -58,20 +64,45 @@ class SalesWithinProvinceLogic extends GetxController {
selectedProductModel.value != null && selectedProductModel.value != null &&
selectedGuildModel.value != null; selectedGuildModel.value != null;
}); });
scrollControllerAllocationsMade.addListener(() {
if (scrollControllerAllocationsMade.position.pixels >=
scrollControllerAllocationsMade.position.maxScrollExtent - 100) {
addPageAllocationsMade.value = true;
getAllocatedMade();
}
});
} }
Future<void> getAllocatedMade() async { Future<void> getAllocatedMade() async {
if (isLoadingMoreAllocationsMade.value ||
!hasMoreDataAllocationsMade.value) {
return;
}
if (addPageAllocationsMade.value) {
currentPageAllocationsMade.value++;
}
safeCall( safeCall(
call: () async => await rootLogic.chickenRepository.getAllocatedMade( call: () async => await rootLogic.chickenRepository.getAllocatedMade(
token: rootLogic.tokenService.accessToken.value!, token: rootLogic.tokenService.accessToken.value!,
page: 1, page: currentPageAllocationsMade.value,
), ),
onSuccess: (result) { onSuccess: (result) {
if (result != null) { if (result != null) {
if (isLoadingMoreAllocationsMade.value &&
allocatedMadeModel.value?.results != null) {
allocatedMadeModel.value?.results?.addAll(result.results!);
} else {
allocatedMadeModel.value = result; allocatedMadeModel.value = result;
} }
}
isLoadingMoreAllocationsMade.value = false;
},
onError: (error, stacktrace) {
isLoadingMoreAllocationsMade.value = false;
}, },
onError: (error, stacktrace) {},
); );
} }
@@ -210,4 +241,12 @@ class SalesWithinProvinceLogic extends GetxController {
onError: (error, stackTrace) {}, onError: (error, stackTrace) {},
); );
} }
@override
void dispose() {
rootLogic.inventoryExpandedList.clear();
super.dispose();
}
} }

View File

@@ -63,7 +63,6 @@ class SalesWithinProvincePage extends GetView<SalesWithinProvinceLogic> {
) )
: ListView.separated( : ListView.separated(
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: controller.rootLogic.inventoryList.length, itemCount: controller.rootLogic.inventoryList.length,
separatorBuilder: (context, index) => separatorBuilder: (context, index) =>
const SizedBox(height: 8), const SizedBox(height: 8),
@@ -94,7 +93,7 @@ class SalesWithinProvincePage extends GetView<SalesWithinProvinceLogic> {
), ),
), ),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
height: expand.keys.contains(index) ? 250 : 80, height: expand.keys.contains(index) ? 300 : 80,
child: inventoryItem( child: inventoryItem(
isExpanded: isExpanded:
expand.keys.contains(index) && expand[index]!, expand.keys.contains(index) && expand[index]!,
@@ -244,10 +243,24 @@ class SalesWithinProvincePage extends GetView<SalesWithinProvinceLogic> {
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),
controller: controller.scrollControllerAllocationsMade,
itemCount: data.value?.results?.length ?? 0, itemCount: data.value?.results?.length ?? 0,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
if (index == data.value!.results!.length) {
return Obx(
() => controller.isLoadingMoreAllocationsMade.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(
color: Colors.white,
margin: const EdgeInsets.symmetric(vertical: 4.0), margin: const EdgeInsets.symmetric(vertical: 4.0),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),