feat : pagination
This commit is contained in:
@@ -220,8 +220,5 @@ class ChickenRepositoryImpl implements ChickenRepository {
|
||||
fromJson: DashboardKillHouseFreeBar.fromJson,
|
||||
);
|
||||
return res.data;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,4 +204,10 @@ class EnteringTheWarehouseLogic extends GetxController {
|
||||
weightLossController.clear();
|
||||
authenticationCodeController.clear();
|
||||
}
|
||||
@override
|
||||
void dispose() {
|
||||
rootLogic.inventoryExpandedList.clear();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
)
|
||||
: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: controller.rootLogic.inventoryList.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(height: 8),
|
||||
@@ -297,17 +296,17 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
height: 700,
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: ListView.separated(
|
||||
controller: controller.scrollControllerWaitingForArrival,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
itemCount: data.value!.results.length+1 ,
|
||||
itemCount: data.value!.results.length + 1,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
|
||||
if (index == data.value!.results!.length) {
|
||||
return Obx(
|
||||
() => controller.isLoadingMoreWaitingForArrival.value
|
||||
() => controller.isLoadingMoreWaitingForArrival.value
|
||||
? const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: const SizedBox(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ class RootLogic extends GetxController {
|
||||
getKillHouseDistributionInfo();
|
||||
}
|
||||
|
||||
|
||||
void toggleExpanded(int index) {
|
||||
if (inventoryExpandedList.keys.contains(index)) {
|
||||
inventoryExpandedList.remove(index);
|
||||
@@ -86,15 +85,14 @@ class RootLogic extends GetxController {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void _handleGeneric(DioException error) {
|
||||
Get.showSnackbar(
|
||||
_errorSnackBar('اعتبار توکن شما منقضی شده است لطفا دوباره وارد شوید'
|
||||
),
|
||||
_errorSnackBar('اعتبار توکن شما منقضی شده است لطفا دوباره وارد شوید'),
|
||||
);
|
||||
tokenService.deleteTokens();
|
||||
Get.offAllNamed(AuthPaths.auth, arguments: Module.chicken );
|
||||
Get.offAllNamed(AuthPaths.auth, arguments: Module.chicken);
|
||||
}
|
||||
|
||||
GetSnackBar _errorSnackBar(String message) {
|
||||
return GetSnackBar(
|
||||
titleText: Text(
|
||||
|
||||
@@ -138,4 +138,10 @@ class SalesWithOutProvinceLogic extends GetxController {
|
||||
}*/
|
||||
|
||||
Future<void> submitAllocation() async {}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
rootLogic.inventoryExpandedList.clear();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,12 @@ class SalesWithinProvinceLogic extends GetxController {
|
||||
final pricePerKiloController = 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
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -58,20 +64,45 @@ class SalesWithinProvinceLogic extends GetxController {
|
||||
selectedProductModel.value != null &&
|
||||
selectedGuildModel.value != null;
|
||||
});
|
||||
|
||||
scrollControllerAllocationsMade.addListener(() {
|
||||
if (scrollControllerAllocationsMade.position.pixels >=
|
||||
scrollControllerAllocationsMade.position.maxScrollExtent - 100) {
|
||||
addPageAllocationsMade.value = true;
|
||||
getAllocatedMade();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getAllocatedMade() async {
|
||||
if (isLoadingMoreAllocationsMade.value ||
|
||||
!hasMoreDataAllocationsMade.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (addPageAllocationsMade.value) {
|
||||
currentPageAllocationsMade.value++;
|
||||
}
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.getAllocatedMade(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
page: 1,
|
||||
page: currentPageAllocationsMade.value,
|
||||
),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
allocatedMadeModel.value = result;
|
||||
if (isLoadingMoreAllocationsMade.value &&
|
||||
allocatedMadeModel.value?.results != null) {
|
||||
allocatedMadeModel.value?.results?.addAll(result.results!);
|
||||
} else {
|
||||
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) {},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
rootLogic.inventoryExpandedList.clear();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ class SalesWithinProvincePage extends GetView<SalesWithinProvinceLogic> {
|
||||
)
|
||||
: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: controller.rootLogic.inventoryList.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(height: 8),
|
||||
@@ -94,7 +93,7 @@ class SalesWithinProvincePage extends GetView<SalesWithinProvinceLogic> {
|
||||
),
|
||||
),
|
||||
duration: const Duration(seconds: 1),
|
||||
height: expand.keys.contains(index) ? 250 : 80,
|
||||
height: expand.keys.contains(index) ? 300 : 80,
|
||||
child: inventoryItem(
|
||||
isExpanded:
|
||||
expand.keys.contains(index) && expand[index]!,
|
||||
@@ -244,10 +243,24 @@ class SalesWithinProvincePage extends GetView<SalesWithinProvinceLogic> {
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
controller: controller.scrollControllerAllocationsMade,
|
||||
itemCount: data.value?.results?.length ?? 0,
|
||||
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];
|
||||
return Card(
|
||||
color: Colors.white,
|
||||
margin: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
|
||||
Reference in New Issue
Block a user