feat : pagination

This commit is contained in:
MrM
2025-06-06 18:13:54 +03:30
parent 9e3629ed1e
commit 9a1e7cc768
3 changed files with 172 additions and 127 deletions

View File

@@ -89,7 +89,7 @@ class ChickenRepositoryImpl implements ChickenRepository {
required int page, required int page,
}) async { }) async {
var res = await _httpClient.get( 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'}, headers: {'Authorization': 'Bearer $token'},
fromJson: ImportedLoadsModel.fromJson, fromJson: ImportedLoadsModel.fromJson,
); );

View File

@@ -18,6 +18,12 @@ class EnteringTheWarehouseLogic extends GetxController {
TextEditingController weightLossController = TextEditingController(); TextEditingController weightLossController = TextEditingController();
TextEditingController authenticationCodeController = 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 @override
void onReady() { void onReady() {
super.onReady(); super.onReady();
@@ -25,6 +31,14 @@ class EnteringTheWarehouseLogic extends GetxController {
getBarGeneralInformation(); getBarGeneralInformation();
getWaitingArrivals(); getWaitingArrivals();
getImportedEntried(); getImportedEntried();
scrollControllerImportedLoad.addListener(() {
if (scrollControllerImportedLoad.position.pixels >=
scrollControllerImportedLoad.position.maxScrollExtent - 100) {
addPageImportedLoad.value = true;
getImportedEntried();
}
});
} }
Future<void> getBarGeneralInformation() async { Future<void> getBarGeneralInformation() async {
@@ -125,19 +139,31 @@ class EnteringTheWarehouseLogic extends GetxController {
} }
Future<void> getImportedEntried() async { Future<void> getImportedEntried() async {
if (isLoadingMoreImportedLoad.value || !hasMoreDataImportedLoad.value) {
return;
}
if (addPageImportedLoad.value) {
currentPageImportedLoad.value++;
}
safeCall( safeCall(
call: () async => await rootLogic.chickenRepository.getImportedLoadsModel( call: () async => await rootLogic.chickenRepository.getImportedLoadsModel(
token: rootLogic.tokenService.accessToken.value!, token: rootLogic.tokenService.accessToken.value!,
page: 1, page: currentPageImportedLoad.value,
), ),
onError: (error, stackTrace) { onError: (error, stackTrace) {
eLog(error); isLoadingMoreImportedLoad.value = false;
}, },
onSuccess: (result) { onSuccess: (result) {
if(result!=null){ if (result != null) {
importedLoads.value = result; if (isLoadingMoreImportedLoad.value && result.results != null) {
importedLoads.value?.results?.addAll(result.results!);
} else {
importedLoads.value = result;
}
isLoadingMoreImportedLoad.value = false;
} }
}, },
); );
} }

View File

@@ -296,8 +296,7 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
margin: const EdgeInsets.symmetric(vertical: 2), margin: const EdgeInsets.symmetric(vertical: 2),
height: 700, height: 700,
padding: const EdgeInsets.all(6), padding: const EdgeInsets.all(6),
child: child: ListView.separated(
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 ?? 0,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
@@ -384,139 +383,159 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
separatorBuilder: (BuildContext context, int index) => separatorBuilder: (BuildContext context, int index) =>
SizedBox(height: 8), SizedBox(height: 8),
), ),
); );
} }
}, controller.waitingForArrival) }, controller.waitingForArrival),
] ],
); );
} }
Widget importedLoads() { Widget importedLoads() {
return Column( return Column(
children: [ children: [
const SizedBox(height: 8), const SizedBox(height: 8),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0), padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Align( child: Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: Text( child: Text(
'بارهای وارد شده', 'بارهای وارد شده',
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal), style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
),
), ),
), ),
ObxValue((data) { ),
if (data.value == null) { ObxValue((data) {
return Container( if (data.value == null) {
height: 80, return Container(
margin: const EdgeInsets.all(8), height: 80,
padding: const EdgeInsets.all(12), margin: const EdgeInsets.all(8),
decoration: BoxDecoration( padding: const EdgeInsets.all(12),
color: Colors.white, decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), color: Colors.white,
border: Border.all(color: AppColor.blueNormal, width: 1), borderRadius: BorderRadius.circular(8),
), border: Border.all(color: AppColor.blueNormal, width: 1),
child: Center(child: CircularProgressIndicator()), ),
); child: Center(child: CircularProgressIndicator()),
} );
else if (data.value?.results?.isEmpty ?? true) { } else if (data.value?.results?.isEmpty ?? true) {
return Container( return Container(
height: 80, height: 80,
margin: const EdgeInsets.all(8), margin: const EdgeInsets.all(8),
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.blueNormal, width: 1), border: Border.all(color: AppColor.blueNormal, width: 1),
), ),
child: Center(child: Text( 'هیچ بار وارد شده‌ای وجود ندارد')), child: Center(child: Text('هیچ بار وارد شده‌ای وجود ندارد')),
); );
} else { } else {
return Container( return Container(
margin: const EdgeInsets.symmetric(vertical: 2), margin: const EdgeInsets.symmetric(vertical: 2),
height: 700, height: 700,
padding: const EdgeInsets.all(6), padding: const EdgeInsets.all(6),
child: child: ListView.separated(
ListView.separated( controller: controller.scrollControllerImportedLoad,
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) {
final result = data.value!.results![index]; if (index == data.value!.results!.length) {
return Card( return Obx(
margin: const EdgeInsets.symmetric(vertical: 4.0), () => controller.isLoadingMoreImportedLoad.value
shape: RoundedRectangleBorder( ? const Padding(
borderRadius: BorderRadius.circular(8), padding: EdgeInsets.symmetric(vertical: 16),
side: const BorderSide( child: Center(child: CircularProgressIndicator()),
color: AppColor.blueNormal, )
width: 1, : const SizedBox(),
),
),
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),
),
); final result = data.value!.results![index];
}
}, controller.importedLoads) 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) { Widget acceptBottomSheet(ResultModel resultModel) {
return BaseBottomSheet( return BaseBottomSheet(
height: 500, height: 500,