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:
190
packages/chicken/lib/features/poultry_science/home/logic.dart
Normal file
190
packages/chicken/lib/features/poultry_science/home/logic.dart
Normal file
@@ -0,0 +1,190 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/poultry_science/home_poultry_science/home_poultry_science_model.dart';
|
||||
import 'package:rasadyar_chicken/features/poultry_science/root/logic.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/custom/information_card_widget.dart';
|
||||
|
||||
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(
|
||||
labelTitle: 'کل فارم ها',
|
||||
isLoading: true,
|
||||
labelVecIcon: Assets.vec.cubeScanSvg.path,
|
||||
iconColor: AppColor.blueFlashing,
|
||||
blendMode: BlendMode.srcOut,
|
||||
valueBgColor: Colors.white,
|
||||
labelGradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [AppColor.blueLight, Colors.white],
|
||||
),
|
||||
),
|
||||
InformationTagData(
|
||||
labelTitle: 'تعداد جوجه ریزی',
|
||||
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],
|
||||
),
|
||||
),
|
||||
],
|
||||
'second': [
|
||||
InformationTagData(
|
||||
labelTitle: 'حجم جوجه ریزی',
|
||||
unit: 'قطعه',
|
||||
isLoading: true,
|
||||
labelVecIcon: Assets.vec.hashtagSvg.path,
|
||||
iconColor: const Color(0xFF6C5D60),
|
||||
labelBgColor: const Color(0xFFDDC0C7),
|
||||
valueBgColor: const Color(0xFFEDDCE0),
|
||||
),
|
||||
InformationTagData(
|
||||
labelTitle: 'مانده در سالن',
|
||||
unit: 'قطعه',
|
||||
isLoading: true,
|
||||
labelVecIcon: Assets.vec.homeHashtagSvg.path,
|
||||
labelBgColor: const Color(0xFFAFCBFF),
|
||||
valueBgColor: const Color(0xFFCEDFFF),
|
||||
),
|
||||
],
|
||||
'third': [
|
||||
InformationTagData(
|
||||
labelTitle: 'تلفات',
|
||||
unit: 'قطعه',
|
||||
isLoading: true,
|
||||
labelVecIcon: Assets.vec.boxRemoveSvg.path,
|
||||
|
||||
iconColor: const Color(0xFF426060),
|
||||
labelBgColor: const Color(0xFFA5D1D2),
|
||||
valueBgColor: const Color(0xFFC7DFE0),
|
||||
),
|
||||
InformationTagData(
|
||||
labelTitle: 'حجم کشتار شده',
|
||||
unit: 'قطعه',
|
||||
isLoading: true,
|
||||
labelVecIcon: Assets.vec.closeSquareFilledSvg.path,
|
||||
blendMode: BlendMode.dst,
|
||||
labelBgColor: Color(0xFFC8B8D1),
|
||||
valueBgColor: Color(0xFFDAD4DD),
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
RxList<InformationCardData> ageCardData = [
|
||||
InformationCardData(
|
||||
labelTitle: 'بیشترین سن جوجه ریزی',
|
||||
isLoading: true,
|
||||
unit: 'روز',
|
||||
labelVecIcon: Assets.vec.homeTrendUpSvg.path,
|
||||
iconColor: const Color.fromRGBO(85, 97, 93, 1),
|
||||
cardBgColor: const Color(0xFFE6FAF5),
|
||||
labelBgColor: const Color(0xFFB0EFDF),
|
||||
),
|
||||
InformationCardData(
|
||||
labelTitle: 'کمترین سن جوجه ریزی',
|
||||
isLoading: true,
|
||||
unit: 'روز',
|
||||
labelVecIcon: Assets.vec.homeTrendDownSvg.path,
|
||||
iconColor: const Color(0xFF6F6164),
|
||||
cardBgColor: const Color(0xFFEDDCE0),
|
||||
labelBgColor: const Color(0xFFE0BCC5),
|
||||
),
|
||||
].obs;
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
getHomePoultryHatching();
|
||||
}
|
||||
|
||||
Future<void> getHomePoultryHatching() async {
|
||||
await safeCall<HomePoultryScienceModel?>(
|
||||
call: () async => await rootLogic.poultryRepository.getHomePoultry(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
type: 'home',
|
||||
),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
homeInformation.value = result;
|
||||
tagInfo['first'] = tagInfo['first']!.map((tag) {
|
||||
if (tag.labelTitle == 'کل فارم ها') {
|
||||
return tag.copyWith(
|
||||
value: result.farmCount?.separatedByCommaFa ?? '0',
|
||||
isLoading: false,
|
||||
);
|
||||
}
|
||||
if (tag.labelTitle == 'تعداد جوجه ریزی') {
|
||||
return tag.copyWith(
|
||||
value: result.hatchingCount?.separatedByCommaFa ?? '0',
|
||||
isLoading: false,
|
||||
);
|
||||
}
|
||||
return tag;
|
||||
}).toList();
|
||||
|
||||
// second
|
||||
tagInfo['second'] = tagInfo['second']!.map((tag) {
|
||||
switch (tag.labelTitle) {
|
||||
case 'حجم جوجه ریزی':
|
||||
return tag.copyWith(
|
||||
value: result.hatchingQuantity?.separatedByCommaFa ?? '0',
|
||||
isLoading: false,
|
||||
);
|
||||
case 'مانده در سالن':
|
||||
return tag.copyWith(
|
||||
value: result.hatchingLeftOver?.separatedByCommaFa ?? '0',
|
||||
isLoading: false,
|
||||
);
|
||||
default:
|
||||
return tag;
|
||||
}
|
||||
}).toList();
|
||||
|
||||
// third
|
||||
tagInfo['third'] = tagInfo['third']!.map((tag) {
|
||||
switch (tag.labelTitle) {
|
||||
case 'تلفات':
|
||||
return tag.copyWith(
|
||||
value: result.hatchingLosses?.separatedByCommaFa ?? '0',
|
||||
isLoading: false,
|
||||
);
|
||||
case 'حجم کشتار شده':
|
||||
return tag.copyWith(
|
||||
value: result.hatchingKilledQuantity?.separatedByCommaFa ?? '0',
|
||||
isLoading: false,
|
||||
);
|
||||
default:
|
||||
return tag;
|
||||
}
|
||||
}).toList();
|
||||
|
||||
ageCardData.value = ageCardData.map((element) {
|
||||
switch (element.labelTitle) {
|
||||
case 'کمترین سن جوجه ریزی':
|
||||
return element.copyWith(
|
||||
value: result.hatchingMinAge?.separatedByCommaFa ?? '0',
|
||||
isLoading: false,
|
||||
);
|
||||
case 'بیشترین سن جوجه ریزی':
|
||||
return element.copyWith(
|
||||
value: result.hatchingMaxAge?.separatedByCommaFa ?? '0',
|
||||
isLoading: false,
|
||||
);
|
||||
default:
|
||||
return element;
|
||||
}
|
||||
}).toList();
|
||||
}
|
||||
},
|
||||
onError: (error, stackTrace) {},
|
||||
);
|
||||
}
|
||||
}
|
||||
393
packages/chicken/lib/features/poultry_science/home/view.dart
Normal file
393
packages/chicken/lib/features/poultry_science/home/view.dart
Normal file
@@ -0,0 +1,393 @@
|
||||
import 'package:flutter/cupertino.dart' hide LinearGradient;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_chicken/presentation/routes/routes.dart';
|
||||
import 'package:rasadyar_chicken/presentation/utils/nested_keys_utils.dart';
|
||||
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/custom/information_card_widget.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
class PoultryScienceHomePage extends GetView<PoultryScienceHomeLogic> {
|
||||
const PoultryScienceHomePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChickenBasePage(
|
||||
isBase: true,
|
||||
hasNotification: true,
|
||||
hasNews: true,
|
||||
scrollable: true,
|
||||
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: 18.h),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
controller.isExpanded.value = !controller.isExpanded.value;
|
||||
},
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsetsGeometry.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(width: 0.50, color: const Color(0xFFA9A9A9)),
|
||||
),
|
||||
|
||||
child: ObxValue((data) {
|
||||
return AnimatedSize(
|
||||
duration: Duration(milliseconds: 300),
|
||||
child: data.value ? mainItemWidget() : mainItemWidgetExpanded(),
|
||||
);
|
||||
}, controller.isExpanded),
|
||||
),
|
||||
Positioned(
|
||||
top: -10,
|
||||
right: 20,
|
||||
child: Container(
|
||||
height: 32.h,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(width: 0.50, color: const Color(0xFFA9A9A9)),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Assets.vec.chicken2Svg.svg(
|
||||
width: 16.w,
|
||||
height: 16.h,
|
||||
colorFilter: ColorFilter.mode(AppColor.blueDark, BlendMode.srcIn),
|
||||
),
|
||||
Text(
|
||||
'اطلاعات فارمها',
|
||||
textAlign: TextAlign.right,
|
||||
style: AppFonts.yekan16Bold.copyWith(color: AppColor.iconColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
widelyWidget(),
|
||||
SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Padding mainItemWidget() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [SizedBox(height: 8), firstTagInformation(), secondTagInformation()],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Padding mainItemWidgetExpanded() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(height: 8),
|
||||
/* Row(
|
||||
spacing: 8,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: ShapeDecoration(
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(width: 0.25, color: const Color(0xFFB0B0B0)),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
child: Assets.images.liveChicken.image(
|
||||
width: 40.w,
|
||||
height: 40.h,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'فارم ها',
|
||||
textAlign: TextAlign.right,
|
||||
style: AppFonts.yekan16.copyWith(color: AppColor.darkGreyDarkActive),
|
||||
),
|
||||
Spacer(),
|
||||
AnimatedRotation(
|
||||
turns: 180,
|
||||
duration: Duration(milliseconds: 3000),
|
||||
child: Icon(CupertinoIcons.chevron_up, size: 18),
|
||||
),
|
||||
],
|
||||
),*/
|
||||
SizedBox(height: 8),
|
||||
firstTagInformation(),
|
||||
Row(
|
||||
children: [
|
||||
Text('اطلاعات جوجهریزی', textAlign: TextAlign.right, style: AppFonts.yekan16),
|
||||
],
|
||||
),
|
||||
secondTagInformation(),
|
||||
thirdTagInformation(),
|
||||
ageCardInformation(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget firstTagInformation() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 13),
|
||||
child: ObxValue((data) {
|
||||
List<InformationTagData>? items = data['first']!;
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: List.generate(
|
||||
items.length,
|
||||
(index) => Expanded(child: InformationTag(data: items[index])),
|
||||
),
|
||||
);
|
||||
}, controller.tagInfo),
|
||||
);
|
||||
}
|
||||
|
||||
Widget secondTagInformation() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 13),
|
||||
child: ObxValue((data) {
|
||||
List<InformationTagData>? items = data['second']!;
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: List.generate(
|
||||
items.length,
|
||||
(index) => Expanded(child: InformationTag(data: items[index])),
|
||||
),
|
||||
);
|
||||
}, controller.tagInfo),
|
||||
);
|
||||
}
|
||||
|
||||
Widget thirdTagInformation() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 13),
|
||||
child: ObxValue((data) {
|
||||
List<InformationTagData>? items = data['third']!;
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: List.generate(
|
||||
items.length,
|
||||
(index) => Expanded(child: InformationTag(data: items[index])),
|
||||
),
|
||||
);
|
||||
}, controller.tagInfo),
|
||||
);
|
||||
}
|
||||
|
||||
Widget ageCardInformation() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(30.w, 8, 30.w, 13),
|
||||
child: ObxValue((data) {
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: List.generate(
|
||||
data.length,
|
||||
(index) => Expanded(child: InformationCard(data: data[index])),
|
||||
),
|
||||
);
|
||||
}, controller.ageCardData),
|
||||
);
|
||||
}
|
||||
|
||||
//region Widely Used Widget
|
||||
Widget widelyWidget() {
|
||||
return Container(
|
||||
margin: EdgeInsetsGeometry.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(width: 0.50, color: const Color(0xFFA9A9A9)),
|
||||
),
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(12.w, 24.h, 12.w, 16.h),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
widelyUsed(
|
||||
title: 'بازرسی',
|
||||
iconPath: Assets.vec.cubeSearchSvg.path,
|
||||
isOnEdit: false,
|
||||
cardColor: AppColor.greenLightActive,
|
||||
labelColor: AppColor.greenNormal,
|
||||
textColor: AppColor.textColor,
|
||||
onTap: () async {
|
||||
controller.rootLogic.currentPage.value = 0;
|
||||
|
||||
Get.toNamed(ChickenRoutes.inspectionPoultryScience, id: poultryFirstKey);
|
||||
},
|
||||
),
|
||||
|
||||
widelyUsed(
|
||||
title: 'ثبت کشتار',
|
||||
iconPath: Assets.vec.noteRemoveSvg.path,
|
||||
isOnEdit: false,
|
||||
cardColor: AppColor.blueLightActive,
|
||||
labelColor: AppColor.blueNormalOld,
|
||||
textColor: AppColor.textColor,
|
||||
onTap: () async {
|
||||
controller.rootLogic.currentPage.value = 0;
|
||||
Get.toNamed(ChickenRoutes.genocidePoultryScience, id: poultryFirstKey);
|
||||
},
|
||||
),
|
||||
widelyUsed(
|
||||
title: 'فارم ها',
|
||||
iconPath: Assets.vec.cubeScanSvg.path,
|
||||
cardColor: Color(0xFFFFCFA3),
|
||||
labelColor: Color(0xFFF68D2B),
|
||||
textColor: AppColor.textColor,
|
||||
isOnEdit: false,
|
||||
onTap: () async {
|
||||
controller.rootLogic.currentPage.value = 0;
|
||||
Get.toNamed(ChickenRoutes.farmPoultryScience, id: poultryFirstKey);
|
||||
},
|
||||
),
|
||||
|
||||
widelyUsed(
|
||||
title: 'جوجهریزی فعال',
|
||||
iconPath: Assets.vec.boxTickSvg.path,
|
||||
isOnEdit: false,
|
||||
cardColor: Color(0xFFD9BEFF),
|
||||
labelColor: Color(0xFF9757FF),
|
||||
textColor: AppColor.textColor,
|
||||
onTap: () async {
|
||||
controller.rootLogic.currentPage.value = 0;
|
||||
Get.toNamed(ChickenRoutes.activeHatchingPoultryScience, id: poultryFirstKey);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: -17,
|
||||
right: 11,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(width: 0.50, color: const Color(0xFFA9A9A9)),
|
||||
),
|
||||
child: Text('پر کاربردها', textAlign: TextAlign.right, style: AppFonts.yekan16),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget widelyUsed({
|
||||
required String title,
|
||||
required String iconPath,
|
||||
required VoidCallback onTap,
|
||||
required bool isOnEdit,
|
||||
Color? cardColor,
|
||||
Color? labelColor,
|
||||
Color? textColor,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: !isOnEdit ? onTap : null,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
spacing: 4,
|
||||
children: [
|
||||
Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: ShapeDecoration(
|
||||
color: cardColor ?? Color(0xFFBECDFF),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: ShapeDecoration(
|
||||
color: labelColor ?? AppColor.blueNormal,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: SvgGenImage.vec(iconPath).svg(
|
||||
width: 24,
|
||||
height: 24,
|
||||
colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: isOnEdit,
|
||||
child: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: ShapeDecoration(
|
||||
color: Colors.white60,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Visibility(
|
||||
visible: isOnEdit,
|
||||
child: Positioned(
|
||||
top: -15,
|
||||
left: -12,
|
||||
child: SizedBox(
|
||||
width: 32.w,
|
||||
height: 32.h,
|
||||
child: GestureDetector(
|
||||
onTap: () {},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 16,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.white),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(CupertinoIcons.minus, color: AppColor.error, size: 15),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
title,
|
||||
style: AppFonts.yekan10Bold.copyWith(color: textColor ?? AppColor.blueNormal),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//endregion
|
||||
}
|
||||
Reference in New Issue
Block a user