feat : farms in poultry science

This commit is contained in:
2025-09-13 11:36:44 +03:30
parent 629f5d2269
commit bf31f4f149
13 changed files with 3023 additions and 4 deletions

View File

@@ -0,0 +1,103 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/data/models/response/poultry/poultry_farm.dart';
import 'package:rasadyar_chicken/presentation/pages/poultry_science/home/logic.dart';
import 'package:rasadyar_chicken/presentation/pages/poultry_science/root/logic.dart';
import 'package:rasadyar_core/core.dart';
class FarmLogic extends GetxController {
List<String> routes = ['اقدام', 'فارم ها'];
PoultryScienceRootLogic rootLogic = Get.find<PoultryScienceRootLogic>();
final PoultryScienceHomeLogic _homeLogic = Get.find<PoultryScienceHomeLogic>();
RxList<InformationTagData> tagInfo = <InformationTagData>[
InformationTagData(
labelTitle: 'کل فارم ها',
isLoading: true,
labelVecIcon: Assets.vec.cubeScanSvg.path,
blendMode: BlendMode.dst,
valueBgColor: Colors.white,
labelGradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [AppColor.blueLight, Colors.white],
),
),
InformationTagData(
labelTitle: 'حجم جوجه ریزی',
unit: 'قطعه',
isLoading: true,
labelVecIcon: Assets.vec.cubeCardSvg.path,
blendMode: BlendMode.dst,
valueBgColor: Colors.white,
labelGradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [AppColor.greenLightHover, Colors.white],
),
),
].obs;
Rx<Resource<PaginationModel<PoultryFarm>>> farmList =
Resource<PaginationModel<PoultryFarm>>.loading().obs;
RxInt currentPage = 1.obs;
final RxBool isLoadingMoreList = false.obs;
RxList<int> isExpandedList = <int>[].obs;
@override
void onReady() {
super.onReady();
tagInfo[0] = tagInfo[0].copyWith(
isLoading: false,
value: _homeLogic.tagInfo['first']!.first.value,
);
tagInfo[1] = tagInfo[1].copyWith(
isLoading: false,
value: _homeLogic.tagInfo['second']!.first.value,
);
getFarmList();
}
@override
void onClose() {
super.onClose();
}
Future<void> getFarmList([bool isLoadingMore = false]) async {
if (isLoadingMore) {
isLoadingMoreList.value = true;
} else {
farmList.value = Resource<PaginationModel<PoultryFarm>>.loading();
}
await safeCall(
call: () async => await rootLogic.poultryRepository.getPoultryScienceFarmList(
token: rootLogic.tokenService.accessToken.value!,
queryParameters: buildQueryParams(
queryParams: {'type': 'farm'},
role: 'PoultryScience',
pageSize: 50,
search: 'filter',
value: '',
page: currentPage.value,
),
),
onSuccess: (res) {
if ((res?.count ?? 0) == 0) {
farmList.value = Resource<PaginationModel<PoultryFarm>>.empty();
} else {
farmList.value = Resource<PaginationModel<PoultryFarm>>.success(
PaginationModel<PoultryFarm>(
count: res?.count ?? 0,
next: res?.next,
previous: res?.previous,
results: [
...(farmList.value.data?.results ?? []),
...?(res?.results as List<PoultryFarm>?),
],
),
);
}
},
onError: (error, stackTrace) {},
);
}
}

View File

@@ -0,0 +1,226 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/data/models/response/poultry/poultry_farm.dart';
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
import 'package:rasadyar_core/core.dart';
import 'logic.dart';
class FarmPage extends GetView<FarmLogic> {
const FarmPage({super.key});
@override
Widget build(BuildContext context) {
return BasePage(
routes: controller.routes,
hasFilter: false,
hasSearch: false,
widgets: [firstTagInformation(), farmListWidget()],
);
}
Widget firstTagInformation() {
return Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 13),
child: ObxValue((data) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 20.w),
child: Row(
spacing: 8,
children: List.generate(
data.length,
(index) => Expanded(child: InformationTag(data: data[index])),
),
),
);
}, controller.tagInfo),
);
}
Widget farmListWidget() {
return Expanded(
child: ObxValue((data) {
return RPaginatedListView(
listType: ListType.separated,
resource: data.value,
hasMore: data.value.data?.next != null,
padding: EdgeInsets.fromLTRB(8, 8, 8, 80),
itemBuilder: (context, index) {
var item = data.value.data!.results![index];
return ObxValue((val) {
return ExpandableListItem2(
selected: val.contains(index),
onTap: () => controller.isExpandedList.toggle(index),
index: index,
child: itemListWidget(item),
secondChild: itemListExpandedWidget(item),
labelColor: AppColor.blueLight,
labelIcon: Assets.vec.checkSquareSvg.path,
);
}, controller.isExpandedList);
},
itemCount: data.value.data?.results?.length ?? 0,
separatorBuilder: (context, index) => SizedBox(height: 8.h),
onLoadMore: () async => controller.getFarmList(true),
onRefresh: () async {
controller.currentPage.value = 1;
await controller.getFarmList();
},
);
}, controller.farmList),
);
}
Container itemListExpandedWidget(PoultryFarm item) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
child: Column(
spacing: 8,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
item.unitName ?? 'N/A',
textAlign: TextAlign.center,
style: AppFonts.yekan16.copyWith(color: AppColor.greenDark),
),
Spacer(),
Visibility(
child: Text(
'${item.address?.province?.name} / ${item.address?.city?.name}',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
),
],
),
Container(
height: 32,
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: ShapeDecoration(
color: AppColor.blueLight,
shape: RoundedRectangleBorder(
side: BorderSide(width: 1, color: AppColor.blueLightHover),
borderRadius: BorderRadius.circular(8),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'تعاونی : ${item.cityOperator ?? 'ندارد'}',
style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
),
Text(
' تعداد سالن : ${item.numberOfHalls}',
style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
),
],
),
),
buildRow(title: 'مالک/ تلفن', value: '${item.user?.fullname} (${item.user?.mobile})'),
buildRow(title: 'شناسه یکتا', value: item.breedingUniqueId ?? 'N/A'),
buildRow(title: 'کد اپیدمیولوژیک', value: item.epidemiologicalCode ?? 'N/A'),
buildRow(title: 'کد بهداشتی', value: item.healthCertificateNumber ?? 'N/A'),
buildRow(
title: 'دامپزشک فارم',
value: '${item.vetFarm?.fullName ?? '-'} (${item.vetFarm?.mobile ?? '-'})',
),
buildRow(title: 'ظرفیت فارم', value: item.totalCapacity.separatedByComma),
buildRow(
title: 'جوجه ریزی فعال (تعداد دوره) ',
value:
'${(item.hatchingInfo?.activeHatching ?? false) ? 'دارد' : 'ندارد'} (${item.hatchingInfo?.period ?? 0})',
),
/* buildRow(
title: 'شرح بازرسی',
value: item.reportInfo?.image == false ? 'ارسال تصویر جوجه ریزی فارم ' : 'تکمیل شده',
titleStyle: AppFonts.yekan14.copyWith(
color: (item.reportInfo?.image ?? false) ? AppColor.greenNormal : AppColor.redDark,
),
valueStyle: AppFonts.yekan14.copyWith(
color: (item.reportInfo?.image ?? false) ? AppColor.greenNormal : AppColor.redDark,
),
),*/
/* Visibility(
visible: (item.reportInfo?.image == false),
child: RElevated(
text: 'ثبت بازرسی',
isFullWidth: true,
width: 150.w,
height: 40.h,
onPressed: () {
cameraBottomSheet(item.id!);
},
textStyle: AppFonts.yekan20.copyWith(color: Colors.white),
backgroundColor: AppColor.greenNormal,
),
),*/
],
),
);
}
Widget itemListWidget(PoultryFarm item) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(width: 20),
Expanded(
flex: 2,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 3,
children: [
Text(
item.unitName ?? 'N/A',
textAlign: TextAlign.start,
style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal),
),
Text(
item.user?.mobile ?? 'N/A',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.bgDark),
),
],
),
),
Expanded(
flex: 3,
child: Column(
spacing: 3,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'شناسه یکتا: ${item.breedingUniqueId}',
textAlign: TextAlign.start,
style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal),
),
Text(
'${item.address?.province?.name}/${item.address?.city?.name}',
textAlign: TextAlign.left,
style: AppFonts.yekan12.copyWith(color: AppColor.bgDark),
),
],
),
),
Expanded(
flex: 1,
child: Assets.vec.scanSvg.svg(
width: 32.w,
height: 32.h,
colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
),
),
],
);
}
}

View File

@@ -8,7 +8,6 @@ class PoultryScienceHomeLogic extends GetxController {
PoultryScienceRootLogic rootLogic = Get.find<PoultryScienceRootLogic>();
Rxn<HomePoultryScienceModel> homeInformation = Rxn();
RxBool isExpanded = false.obs;
RxMap<String, List<InformationTagData>> tagInfo = RxMap({
'first': [
InformationTagData(
@@ -55,7 +54,6 @@ class PoultryScienceHomeLogic extends GetxController {
valueBgColor: const Color(0xFFCEDFFF),
),
],
'third': [
InformationTagData(
labelTitle: 'تلفات',

View File

@@ -80,6 +80,7 @@ class InspectionPoultryScienceLogic extends GetxController {
token: rootLogic.tokenService.accessToken.value!,
queryParameters: buildQueryParams(
queryParams: {'type': 'hatching', 'report': true},
role: 'PoultryScience',
pageSize: 50,
page: currentPage.value,
),