refactor: update data source and repository structure by removing unused files, enhancing model integration, and adjusting import paths for better organization

This commit is contained in:
2025-12-07 12:33:39 +03:30
parent c28a4a3177
commit 02686115cb
129 changed files with 5269 additions and 545 deletions

View File

@@ -0,0 +1,116 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/data/models/response/poultry_farm/poultry_farm.dart';
import 'package:rasadyar_chicken/features/poultry_science/home/logic.dart';
import 'package:rasadyar_chicken/features/poultry_science/root/logic.dart';
import 'package:rasadyar_core/core.dart';
class FarmLogic extends GetxController {
List<String> routes = ['اقدام', 'فارم ها'];
PoultryScienceRootLogic rootLogic = Get.find<PoultryScienceRootLogic>();
BasePageLogic baseLogic = Get.find<BasePageLogic>();
final PoultryScienceHomeLogic _homeLogic = Get.find<PoultryScienceHomeLogic>();
RxList<InformationTagData> tagInfo = <InformationTagData>[
InformationTagData(
labelTitle: 'کل فارم ها',
isLoading: true,
labelVecIcon: Assets.vec.cubeScanSvg.path,
iconColor: AppColor.blueNormalOld,
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;
RxInt expandedIndex = RxInt(-1);
Rx<Jalali> fromDateFilter = Jalali.now().obs;
Rx<Jalali> toDateFilter = Jalali.now().obs;
RxnString searchedValue = RxnString();
@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();
baseLogic.clearSearch();
}
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],
),
);
}
},
onError: (error, stackTrace) {},
);
}
void toggleExpanded(int index) {
expandedIndex.value = expandedIndex.value == index ? -1 : index;
}
Future<void> onRefresh() async {
currentPage.value = 1;
farmList.value = Resource<PaginationModel<PoultryFarm>>.loading();
await getFarmList();
}
}

View File

@@ -0,0 +1,250 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/data/models/response/poultry_farm/poultry_farm.dart';
import 'package:rasadyar_chicken/presentation/utils/nested_keys_utils.dart';
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
import 'package:rasadyar_chicken/presentation/widget/filter_bottom_sheet.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 ChickenBasePage(
hasFilter: false,
hasSearch: true,
onRefresh: controller.onRefresh,
onFilterTap: () {
Get.bottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
filterBottomSheet(),
);
},
onSearchChanged: (data) {
controller.searchedValue.value = data;
controller.getFarmList();
},
routes: controller.routes,
backId: poultryFirstKey,
child: Column(children: [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.value.isEqual(index),
onTap: () => controller.toggleExpanded(index),
index: index,
child: itemListWidget(item),
secondChild: itemListExpandedWidget(item),
labelColor: AppColor.blueLight,
labelIcon: Assets.vec.cubeScanSvg.path,
);
}, controller.expandedIndex);
},
itemCount: data.value.data?.results?.length ?? 0,
separatorBuilder: (context, index) => SizedBox(height: 8.h),
onLoadMore: () async => controller.getFarmList(true),
);
}, 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 ?? '-'})',
),
buildUnitRow(
title: 'ظرفیت فارم',
value: item.totalCapacity.separatedByCommaFa,
unit: '(قطعه)',
),
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),
),
),
],
);
}
Widget filterBottomSheet() => filterBottomSheetWidget(
fromDate: controller.fromDateFilter,
onChangedFromDate: (jalali) => controller.fromDateFilter.value = jalali,
toDate: controller.toDateFilter,
onChangedToDate: (jalali) => controller.toDateFilter.value = jalali,
onSubmit: () => controller.getFarmList(),
);
}