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) {
if (isLoadingMoreImportedLoad.value && result.results != null) {
importedLoads.value?.results?.addAll(result.results!);
} else {
importedLoads.value = result; 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,11 +383,10 @@ 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),
] ],
); );
} }
@@ -419,8 +417,7 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
), ),
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),
@@ -430,20 +427,33 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
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) {
if (index == data.value!.results!.length) {
return Obx(
() => controller.isLoadingMoreImportedLoad.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),
@@ -469,7 +479,8 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
), ),
buildRow( buildRow(
'مشخصات خریدار', 'مشخصات خریدار',
'${result.toSteward?.user?.fullname} - ${result.toSteward?.guildsName}' ?? 'N/A', '${result.toSteward?.user?.fullname} - ${result.toSteward?.guildsName}' ??
'N/A',
), ),
buildRow( buildRow(
'مشخصات فروشنده', 'مشخصات فروشنده',
@@ -491,11 +502,25 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
'وزن تخصیصی', 'وزن تخصیصی',
'${result.weightOfCarcasses?.toInt() ?? 0} کیلوگرم', '${result.weightOfCarcasses?.toInt() ?? 0} کیلوگرم',
), ),
buildRow('کداحراز', result.registrationCode?.toString() ?? 'N/A'), buildRow(
buildRow('وضعیت کد احراز', result.systemRegistrationCode == true ?"ارسال شده":"ارسال نشده" ?? 'N/A'), 'کداحراز',
buildRow('افت وزن(کیلوگرم)', result.weightLossOfCarcasses?.toInt().toString() ?? 'N/A'), result.registrationCode?.toString() ?? 'N/A',
buildRow('وضعیت', result.receiverState?.faItem ?? 'N/A'), ),
buildRow(
'وضعیت کد احراز',
result.systemRegistrationCode == true
? "ارسال شده"
: "ارسال نشده" ?? 'N/A',
),
buildRow(
'افت وزن(کیلوگرم)',
result.weightLossOfCarcasses?.toInt().toString() ??
'N/A',
),
buildRow(
'وضعیت',
result.receiverState?.faItem ?? 'N/A',
),
], ],
), ),
), ),
@@ -504,19 +529,13 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
separatorBuilder: (BuildContext context, int index) => separatorBuilder: (BuildContext context, int index) =>
SizedBox(height: 8), SizedBox(height: 8),
), ),
); );
} }
}, controller.importedLoads) }, controller.importedLoads),
] ],
); );
} }
Widget acceptBottomSheet(ResultModel resultModel) { Widget acceptBottomSheet(ResultModel resultModel) {
return BaseBottomSheet( return BaseBottomSheet(
height: 500, height: 500,