feat : chicken root page , inventory , sale in province

This commit is contained in:
MrM
2025-06-05 23:26:44 +03:30
parent 5849466e3b
commit 1cfcf9fa8f
68 changed files with 16615 additions and 126 deletions

View File

@@ -1,33 +1,115 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' show Text, EdgeInsets, Colors;
import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart';
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
import 'package:rasadyar_auth/data/utils/safe_call.dart';
import 'package:rasadyar_auth/presentation/routes/pages.dart';
import 'package:rasadyar_chicken/data/models/response/inventory/inventory_model.dart';
import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository_imp.dart';
import 'package:rasadyar_core/core.dart';
enum ErrorLocationType { serviceDisabled, permissionDenied, none }
class RootLogic extends GetxController {
RxInt currentIndex = 0.obs;
List<Widget> pages = [
Container(color: Colors.deepOrange,),
Container(color: Colors.amberAccent,),
Container(color: Colors.black,),
];
RxList<ErrorLocationType> errorLocationType = RxList();
RxMap<int, dynamic> inventoryExpandedList = RxMap();
var tokenService = Get.find<TokenStorageService>();
late ChickenRepository chickenRepository;
late DioRemote dioRemote;
RxInt count = 5.obs;
RxList<InventoryModel> inventoryList = RxList();
Rxn<KillHouseDistributionInfo> killHouseDistributionInfo =
Rxn<KillHouseDistributionInfo>();
@override
void onReady() {
super.onReady();
void onInit() {
super.onInit();
dioRemote = DioRemote(baseUrl: tokenService.baseurl.value);
dioRemote.init();
chickenRepository = ChickenRepositoryImpl(dioRemote);
getInventory();
getKillHouseDistributionInfo();
}
void changePage(int index) {
currentIndex.value = index;
void toggleExpanded(int index) {
if (inventoryExpandedList.keys.contains(index)) {
inventoryExpandedList.remove(index);
} else {
inventoryExpandedList[index] = false;
}
}
@override
void onClose() {
// TODO: implement onClose
super.onClose();
Future<void> getInventory() async {
await safeCall<List<InventoryModel>?>(
call: () async => await chickenRepository.getInventory(
token: tokenService.accessToken.value!,
),
onSuccess: (result) {
if (result != null) {
iLog(result);
inventoryList.clear();
inventoryList.addAll(result);
iLog(inventoryList);
}
},
onError: (error, stackTrace) {
switch (error.response?.statusCode) {
case 401:
_handleGeneric(error);
break;
case 403:
_handleGeneric(error);
break;
default:
_handleGeneric(error);
}
},
);
}
Future<void> getKillHouseDistributionInfo() async {
await safeCall<KillHouseDistributionInfo?>(
call: () async => await chickenRepository.getIKillHouseDistributionInfo(
token: tokenService.accessToken.value!,
),
onSuccess: (result) {
if (result != null) {
iLog(result);
killHouseDistributionInfo.value = result;
iLog(killHouseDistributionInfo.value);
}
},
onError: (error, stackTrace) {},
);
}
void _handleGeneric(DioException error) {
Get.showSnackbar(
_errorSnackBar('اعتبار توکن شما منقضی شده است لطفا دوباره وارد شوید'
),
);
tokenService.deleteTokens();
Get.offAllNamed(AuthPaths.auth, arguments: Module.chicken );
}
GetSnackBar _errorSnackBar(String message) {
return GetSnackBar(
titleText: Text(
'خطا',
style: AppFonts.yekan14.copyWith(color: Colors.white),
),
messageText: Text(
message,
style: AppFonts.yekan12.copyWith(color: Colors.white),
),
backgroundColor: AppColor.error,
margin: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
borderRadius: 12,
duration: Duration(milliseconds: 3500),
snackPosition: SnackPosition.TOP,
);
}
}

View File

@@ -1,82 +1,455 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/chicken.dart';
import 'package:rasadyar_chicken/data/models/response/inventory/inventory_model.dart';
import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart';
import 'package:rasadyar_core/core.dart';
import 'logic.dart';
class RootPage extends GetView<RootLogic> {
const RootPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
ObxValue(
(currentIndex) => IndexedStack(
index: currentIndex.value,
children: controller.pages,
appBar: RAppBar(title: 'مدیریت انبار', centerTitle: true, hasBack: false),
body: SingleChildScrollView(
child: Column(
children: [
inventoryWidget(),
ObxValue(
(data) => broadcastInformationWidget(data.value),
controller.killHouseDistributionInfo,
),
controller.currentIndex,
),
],
),
bottomNavigationBar: WaveBottomNavigation(
items: [
WaveBottomNavigationItem(title: 'خانه', icon: Assets.vec.mapSvg.svg(
width: 32,
height: 32,
colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),
)),
WaveBottomNavigationItem(
title: 'عملیات',
icon: Assets.vec.userSvg.svg(
width: 32,
height: 32,
colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),
SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
cardWidget(
title: 'ورود به انبار',
iconPath: Assets.icons.whareHouse.path,
onTap: () {
Get.toNamed(ChickenRoutes.enteringTheWarehouse);
},
),
cardWidget(
title: 'فروش داخل استان',
iconPath: Assets.icons.inside.path,
onTap: () {
Get.toNamed(ChickenRoutes.salesWithinProvince);
},
),
cardWidget(
title: 'فروش خارج استان',
iconPath: Assets.icons.outside.path,
onTap: () {},
),
],
),
),
),
WaveBottomNavigationItem(
title: 'افزودن',
icon: Assets.vec.addSvg.svg(
width: 32,
height: 32,
colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),
),
),
WaveBottomNavigationItem(
title: 'آمار',
icon: Assets.vec.diagramSvg.svg(width: 32,height: 32,colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),),
),
WaveBottomNavigationItem(
title: 'تماس',
icon: Assets.vec.callSvg.svg(
width: 32,
height: 32,
colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),
),
),
WaveBottomNavigationItem(
title: 'مکان ',
icon: Assets.vec.gpsSvg.svg(
width: 32,
height: 32,
colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),
),
),
WaveBottomNavigationItem(
title: 'تاریخ',
icon: Assets.vec.calendarSvg.svg(
width: 32,
height: 32,
colorFilter: ColorFilter.mode(Colors.white, BlendMode.srcIn),
),
),
],
onPageChanged: (index) {
controller.changePage(index);
},
],
),
),
);
}
Widget inventoryWidget() {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
children: [
const SizedBox(height: 20),
Align(
alignment: Alignment.centerRight,
child: Text(
'موجودی انبار',
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
),
),
SizedBox(height: 4),
ObxValue(
(data) => data.isEmpty
? Container(
margin: const EdgeInsets.symmetric(vertical: 2),
height: 80,
padding: EdgeInsets.all(6),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.blueNormal, width: 1),
),
child: Center(child: CircularProgressIndicator()),
)
: ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: controller.inventoryList.length,
separatorBuilder: (context, index) =>
const SizedBox(height: 8),
itemBuilder: (context, index) {
return ObxValue((expand) {
return GestureDetector(
onTap: () {
controller.toggleExpanded(index);
},
behavior: HitTestBehavior.opaque,
child: AnimatedContainer(
onEnd: () {
controller.inventoryExpandedList[index] =
!controller.inventoryExpandedList[index]!;
},
margin: const EdgeInsets.symmetric(vertical: 2),
padding: EdgeInsets.all(6),
curve: Curves.easeInOut,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: AppColor.blueNormal,
width: 1,
),
),
duration: const Duration(seconds: 1),
height: expand.keys.contains(index) ? 250 : 80,
child: inventoryItem(
isExpanded:
expand.keys.contains(index) && expand[index]!,
index: index,
model: controller.inventoryList[index],
),
),
);
}, controller.inventoryExpandedList);
},
),
controller.inventoryList,
),
],
),
);
}
Widget inventoryItem({
required bool isExpanded,
required int index,
required InventoryModel model,
}) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 8,
children: [
buildRow('نام محصول', model.name ?? ''),
Visibility(
visible: isExpanded,
child: Column(
spacing: 8,
children: [
buildRow('وزن خریدهای دولتی داخل استان (کیلوگرم)', '0326598653'),
buildRow(
'وزن خریدهای آزاد داخل استان (کیلوگرم)',
model.receiveFreeCarcassesWeight.toString(),
),
buildRow(
'وزن خریدهای خارج استان (کیلوگرم)',
model.freeBuyingCarcassesWeight.toString(),
),
buildRow(
'کل ورودی به انبار (کیلوگرم)',
model.totalFreeBarsCarcassesWeight.toString(),
),
buildRow(
'کل فروش (کیلوگرم)',
model.realAllocatedWeight.toString(),
),
buildRow(
'مانده انبار (کیلوگرم)',
model.totalRemainWeight.toString(),
),
],
),
),
],
);
}
Widget buildRow(String title, String value) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 2,
child: Text(
title,
textAlign: TextAlign.right,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
),
Flexible(
flex: 1,
child: Text(
value,
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
),
],
),
);
}
Widget broadcastInformationWidget(KillHouseDistributionInfo? model) {
return Container(
height: 140,
margin: const EdgeInsets.all(8),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.blueNormal, width: 1),
),
child: model != null
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 10,
children: [
Text(
'اطلاعات ارسالی',
textAlign: TextAlign.right,
style: AppFonts.yekan16Bold.copyWith(
color: AppColor.blueNormal,
),
),
const SizedBox(height: 12),
buildRow(
'فروش و توزیع داخل استان (کیلوگرم)',
model.stewardAllocationsWeight!.toInt().toString(),
),
buildRow(
'فروش و توزیع خارج استان (کیلوگرم)',
model.freeSalesWeight!.toInt().toString(),
),
],
)
: const Center(child: CircularProgressIndicator()),
);
}
}
Widget expandedContainer(bool isExpanded, VoidCallback onTap) {
return AnimatedContainer(
margin: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
curve: Curves.easeInOut,
duration: Duration(seconds: 1),
height: isExpanded ? 364 : 80,
child: markerDetailsWidget(ontap: onTap),
);
}
Widget markerDetailsWidget({required VoidCallback ontap}) {
return GestureDetector(
onTap: ontap,
behavior: HitTestBehavior.opaque,
child: Container(
clipBehavior: Clip.antiAlias,
padding: EdgeInsets.symmetric(horizontal: 0, vertical: 10),
decoration: ShapeDecoration(
color: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: Column(
spacing: 15,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
spacing: 12,
children: [
vecWidgetWithOnTap(
child: Assets.vec.editSvg.svg(),
onTap: () {},
width: 24,
height: 24,
color: AppColor.blueNormal,
),
Text(
'سوابق بازرسی من',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
vecWidgetWithOnTap(
child: Assets.vec.trashSvg.svg(),
width: 24,
height: 24,
color: AppColor.redNormal,
onTap: () {},
),
],
),
Container(
height: 32,
clipBehavior: Clip.antiAlias,
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: ShapeDecoration(
color: AppColor.blueLight,
shape: RoundedRectangleBorder(
side: BorderSide(width: 1, color: AppColor.blueLightHover),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'تاریخ بازرسی',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
Text(
'1403/12/12',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'شماره همراه',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
Text(
'0326598653',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'آخرین فعالیت',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
Text(
'1409/12/12',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'موجودی',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
Text(
'5کیلوگرم',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
],
),
...List.generate(
5,
(index) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'فروش رفته',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
Text(
'0 کیلوگرم',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(
color: AppColor.darkGreyDarkHover,
),
),
],
),
),
],
),
),
);
}
Widget cardWidget({
required String title,
required String iconPath,
required VoidCallback onTap,
}) {
return Container(
width: Get.width / 4,
height: 130,
child: GestureDetector(
onTap: onTap,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide(width: 1, color: AppColor.blueNormal),
),
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SvgGenImage(iconPath).svg(width: 50, height: 50),
SizedBox(height: 4),
Text(
title,
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal),
),
],
),
),
),
),
);
}