diff --git a/packages/chicken/lib/data/repositories/chicken_repository_imp.dart b/packages/chicken/lib/data/repositories/chicken_repository_imp.dart index 6990d79..a6c3631 100644 --- a/packages/chicken/lib/data/repositories/chicken_repository_imp.dart +++ b/packages/chicken/lib/data/repositories/chicken_repository_imp.dart @@ -89,7 +89,7 @@ class ChickenRepositoryImpl implements ChickenRepository { required int page, }) async { var res = await _httpClient.get( - '/steward-allocation/?role=Steward&search=filter&page=${page}&page_size=10&value=&type=entered', + '/steward-allocation/?role=Steward&search=filter&page=$page&page_size=10&value=&type=entered', headers: {'Authorization': 'Bearer $token'}, fromJson: ImportedLoadsModel.fromJson, ); diff --git a/packages/chicken/lib/presentation/pages/entering_the_warehouse/logic.dart b/packages/chicken/lib/presentation/pages/entering_the_warehouse/logic.dart index 366f449..f156845 100644 --- a/packages/chicken/lib/presentation/pages/entering_the_warehouse/logic.dart +++ b/packages/chicken/lib/presentation/pages/entering_the_warehouse/logic.dart @@ -18,6 +18,12 @@ class EnteringTheWarehouseLogic extends GetxController { TextEditingController weightLossController = TextEditingController(); TextEditingController authenticationCodeController = TextEditingController(); + final ScrollController scrollControllerImportedLoad = ScrollController(); + final RxInt currentPageImportedLoad = 1.obs; + final RxBool isLoadingMoreImportedLoad = false.obs; + final RxBool addPageImportedLoad = false.obs; + final RxBool hasMoreDataImportedLoad = true.obs; + @override void onReady() { super.onReady(); @@ -25,6 +31,14 @@ class EnteringTheWarehouseLogic extends GetxController { getBarGeneralInformation(); getWaitingArrivals(); getImportedEntried(); + + scrollControllerImportedLoad.addListener(() { + if (scrollControllerImportedLoad.position.pixels >= + scrollControllerImportedLoad.position.maxScrollExtent - 100) { + addPageImportedLoad.value = true; + getImportedEntried(); + } + }); } Future getBarGeneralInformation() async { @@ -125,19 +139,31 @@ class EnteringTheWarehouseLogic extends GetxController { } Future getImportedEntried() async { + if (isLoadingMoreImportedLoad.value || !hasMoreDataImportedLoad.value) { + return; + } + + if (addPageImportedLoad.value) { + currentPageImportedLoad.value++; + } + safeCall( call: () async => await rootLogic.chickenRepository.getImportedLoadsModel( token: rootLogic.tokenService.accessToken.value!, - page: 1, + page: currentPageImportedLoad.value, ), onError: (error, stackTrace) { - eLog(error); + isLoadingMoreImportedLoad.value = false; }, onSuccess: (result) { - if(result!=null){ - importedLoads.value = result; + if (result != null) { + if (isLoadingMoreImportedLoad.value && result.results != null) { + importedLoads.value?.results?.addAll(result.results!); + } else { + importedLoads.value = result; + } + isLoadingMoreImportedLoad.value = false; } - }, ); } diff --git a/packages/chicken/lib/presentation/pages/entering_the_warehouse/view.dart b/packages/chicken/lib/presentation/pages/entering_the_warehouse/view.dart index 0bff7d7..f998308 100644 --- a/packages/chicken/lib/presentation/pages/entering_the_warehouse/view.dart +++ b/packages/chicken/lib/presentation/pages/entering_the_warehouse/view.dart @@ -296,8 +296,7 @@ class EnteringTheWarehousePage extends GetView { margin: const EdgeInsets.symmetric(vertical: 2), height: 700, padding: const EdgeInsets.all(6), - child: - ListView.separated( + child: ListView.separated( padding: const EdgeInsets.all(8.0), itemCount: data.value?.results.length ?? 0, itemBuilder: (BuildContext context, int index) { @@ -384,139 +383,159 @@ class EnteringTheWarehousePage extends GetView { separatorBuilder: (BuildContext context, int index) => SizedBox(height: 8), ), - ); } - }, controller.waitingForArrival) - ] + }, controller.waitingForArrival), + ], ); } Widget importedLoads() { return Column( - children: [ - const SizedBox(height: 8), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 8.0), - child: Align( - alignment: Alignment.centerRight, - child: Text( - 'بارهای وارد شده', - style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal), - ), + children: [ + const SizedBox(height: 8), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Align( + alignment: Alignment.centerRight, + child: Text( + 'بارهای وارد شده', + style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal), ), ), - ObxValue((data) { - if (data.value == null) { - return Container( - height: 80, - margin: const EdgeInsets.all(8), - padding: const EdgeInsets.all(12), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - border: Border.all(color: AppColor.blueNormal, width: 1), - ), - child: Center(child: CircularProgressIndicator()), - ); - } - else if (data.value?.results?.isEmpty ?? true) { - return Container( - height: 80, - margin: const EdgeInsets.all(8), - padding: const EdgeInsets.all(12), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - border: Border.all(color: AppColor.blueNormal, width: 1), - ), - child: Center(child: Text( 'هیچ بار وارد شده‌ای وجود ندارد')), - ); - } else { - return Container( - margin: const EdgeInsets.symmetric(vertical: 2), - height: 700, - padding: const EdgeInsets.all(6), - child: - ListView.separated( - padding: const EdgeInsets.all(8.0), - itemCount: data.value?.results?.length ?? 0, - itemBuilder: (BuildContext context, int index) { - final result = data.value!.results![index]; - return Card( - margin: const EdgeInsets.symmetric(vertical: 4.0), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - side: const BorderSide( - color: AppColor.blueNormal, - width: 1, - ), - ), - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - buildRow('ردیف', '${index + 1}'), - buildRow( - 'تاریخ ثبت', - result.date!.formattedJalaliDate ?? 'N/A', - ), - buildRow( - 'نوع تخصیص', - result.allocationType?.faAllocationType ?? 'N/A', - ), - buildRow( - 'مشخصات خریدار', - '${result.toSteward?.user?.fullname} - ${result.toSteward?.guildsName}' ?? 'N/A', - ), - buildRow( - 'مشخصات فروشنده', - result.killHouse?.name ?? 'N/A', - ), - buildRow( - 'نوع فروش', - result.sellType?.faItem ?? 'N/A', - ), - buildRow( - 'قیمت هر کیلو', - '${result.amount ?? 0} ریال ', - ), - buildRow( - 'قیمت کل', - '${result.totalAmount ?? 0} ریال', - ), - buildRow( - 'وزن تخصیصی', - '${result.weightOfCarcasses?.toInt() ?? 0} کیلوگرم', - ), - buildRow('کداحراز', result.registrationCode?.toString() ?? 'N/A'), - buildRow('وضعیت کد احراز', result.systemRegistrationCode == true ?"ارسال شده":"ارسال نشده" ?? 'N/A'), - buildRow('افت وزن(کیلوگرم)', result.weightLossOfCarcasses?.toInt().toString() ?? 'N/A'), - buildRow('وضعیت', result.receiverState?.faItem ?? 'N/A'), - - ], - ), - ), + ), + ObxValue((data) { + if (data.value == null) { + return Container( + height: 80, + margin: const EdgeInsets.all(8), + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + border: Border.all(color: AppColor.blueNormal, width: 1), + ), + child: Center(child: CircularProgressIndicator()), + ); + } else if (data.value?.results?.isEmpty ?? true) { + return Container( + height: 80, + margin: const EdgeInsets.all(8), + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + border: Border.all(color: AppColor.blueNormal, width: 1), + ), + child: Center(child: Text('هیچ بار وارد شده‌ای وجود ندارد')), + ); + } else { + return Container( + margin: const EdgeInsets.symmetric(vertical: 2), + height: 700, + padding: const EdgeInsets.all(6), + child: ListView.separated( + controller: controller.scrollControllerImportedLoad, + padding: const EdgeInsets.all(8.0), + itemCount: data.value!.results!.length + 1, + itemBuilder: (BuildContext context, int index) { + if (index == data.value!.results!.length) { + return Obx( + () => controller.isLoadingMoreImportedLoad.value + ? const Padding( + padding: EdgeInsets.symmetric(vertical: 16), + child: Center(child: CircularProgressIndicator()), + ) + : const SizedBox(), ); - }, - separatorBuilder: (BuildContext context, int index) => - SizedBox(height: 8), - ), + } - ); - } - }, controller.importedLoads) - ] + final result = data.value!.results![index]; + + return Card( + color: Colors.white, + margin: const EdgeInsets.symmetric(vertical: 4.0), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: const BorderSide( + color: AppColor.blueNormal, + width: 1, + ), + ), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + buildRow('ردیف', '${index + 1}'), + buildRow( + 'تاریخ ثبت', + result.date!.formattedJalaliDate ?? 'N/A', + ), + buildRow( + 'نوع تخصیص', + result.allocationType?.faAllocationType ?? 'N/A', + ), + buildRow( + 'مشخصات خریدار', + '${result.toSteward?.user?.fullname} - ${result.toSteward?.guildsName}' ?? + 'N/A', + ), + buildRow( + 'مشخصات فروشنده', + result.killHouse?.name ?? 'N/A', + ), + buildRow( + 'نوع فروش', + result.sellType?.faItem ?? 'N/A', + ), + buildRow( + 'قیمت هر کیلو', + '${result.amount ?? 0} ریال ', + ), + buildRow( + 'قیمت کل', + '${result.totalAmount ?? 0} ریال', + ), + buildRow( + 'وزن تخصیصی', + '${result.weightOfCarcasses?.toInt() ?? 0} کیلوگرم', + ), + buildRow( + 'کداحراز', + result.registrationCode?.toString() ?? 'N/A', + ), + buildRow( + 'وضعیت کد احراز', + result.systemRegistrationCode == true + ? "ارسال شده" + : "ارسال نشده" ?? 'N/A', + ), + buildRow( + 'افت وزن(کیلوگرم)', + result.weightLossOfCarcasses?.toInt().toString() ?? + 'N/A', + ), + buildRow( + 'وضعیت', + result.receiverState?.faItem ?? 'N/A', + ), + ], + ), + ), + ); + }, + separatorBuilder: (BuildContext context, int index) => + SizedBox(height: 8), + ), + ); + } + }, controller.importedLoads), + ], ); } - - - - - Widget acceptBottomSheet(ResultModel resultModel) { return BaseBottomSheet( height: 500,