feat : pagination
This commit is contained in:
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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<void> getBarGeneralInformation() async {
|
||||
@@ -125,19 +139,31 @@ class EnteringTheWarehouseLogic extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> 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) {
|
||||
if (isLoadingMoreImportedLoad.value && result.results != null) {
|
||||
importedLoads.value?.results?.addAll(result.results!);
|
||||
} else {
|
||||
importedLoads.value = result;
|
||||
}
|
||||
|
||||
isLoadingMoreImportedLoad.value = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -296,8 +296,7 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
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,11 +383,10 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
SizedBox(height: 8),
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
}, controller.waitingForArrival)
|
||||
]
|
||||
}, controller.waitingForArrival),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -419,8 +417,7 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
else if (data.value?.results?.isEmpty ?? true) {
|
||||
} else if (data.value?.results?.isEmpty ?? true) {
|
||||
return Container(
|
||||
height: 80,
|
||||
margin: const EdgeInsets.all(8),
|
||||
@@ -437,13 +434,26 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
margin: const EdgeInsets.symmetric(vertical: 2),
|
||||
height: 700,
|
||||
padding: const EdgeInsets.all(6),
|
||||
child:
|
||||
ListView.separated(
|
||||
child: ListView.separated(
|
||||
controller: controller.scrollControllerImportedLoad,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
itemCount: data.value?.results?.length ?? 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(),
|
||||
);
|
||||
}
|
||||
|
||||
final result = data.value!.results![index];
|
||||
|
||||
return Card(
|
||||
color: Colors.white,
|
||||
margin: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@@ -469,7 +479,8 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
),
|
||||
buildRow(
|
||||
'مشخصات خریدار',
|
||||
'${result.toSteward?.user?.fullname} - ${result.toSteward?.guildsName}' ?? 'N/A',
|
||||
'${result.toSteward?.user?.fullname} - ${result.toSteward?.guildsName}' ??
|
||||
'N/A',
|
||||
),
|
||||
buildRow(
|
||||
'مشخصات فروشنده',
|
||||
@@ -491,11 +502,25 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
'وزن تخصیصی',
|
||||
'${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'),
|
||||
|
||||
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',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -504,19 +529,13 @@ class EnteringTheWarehousePage extends GetView<EnteringTheWarehouseLogic> {
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
SizedBox(height: 8),
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
}, controller.importedLoads)
|
||||
]
|
||||
}, controller.importedLoads),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Widget acceptBottomSheet(ResultModel resultModel) {
|
||||
return BaseBottomSheet(
|
||||
height: 500,
|
||||
|
||||
Reference in New Issue
Block a user