feat : home page

This commit is contained in:
2025-06-15 17:16:04 +03:30
parent 448834ecb2
commit 77d5f3be3e
20 changed files with 540 additions and 262 deletions

View File

@@ -1,17 +1,103 @@
import 'package:rasadyar_auth/data/utils/safe_call.dart';
import 'package:rasadyar_chicken/chicken.dart';
import 'package:rasadyar_chicken/data/models/response/bar_information/bar_information.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/presentation/utils/utils.dart';
import 'package:rasadyar_core/core.dart';
class HomeLogic extends GetxController {
RootLogic root = Get.find<RootLogic>();
RxnInt totalWeightTodayBars = RxnInt();
Rxn<InventoryModel> inventoryModel = Rxn<InventoryModel>();
Rxn<KillHouseDistributionInfo> killHouseDistributionInfo = Rxn<KillHouseDistributionInfo>();
@override
void onInit() {
super.onInit();
getTodayBars();
getInventory();
getDistributionInformation();
}
Future<void> getTodayBars() async {
await safeCall<BarInformation?>(
call: () async => await root.chickenRepository.getGeneralBarInformation(
token: root.tokenService.accessToken.value!,
queryParameters: buildQueryParams(fromDate: DateTime.now(), toDate: DateTime.now()),
),
onSuccess: (result) {
if (result != null) {
totalWeightTodayBars.value = result.totalBarsWeight?.toInt();
}
},
onError: (error, stackTrace) {
switch (error.response?.statusCode) {
case 401:
errorHandler(error);
break;
case 403:
errorHandler(error);
break;
default:
errorHandler(error);
}
},
);
}
Future<void> getInventory() async {
await safeCall<List<InventoryModel>?>(
call: () async => await root.chickenRepository.getInventory(token: root.tokenService.accessToken.value!),
onSuccess: (result) {
if (result != null) {
inventoryModel.value = result.first;
}
},
onError: (error, stackTrace) {
switch (error.response?.statusCode) {
case 401:
errorHandler(error);
break;
case 403:
errorHandler(error);
break;
default:
errorHandler(error);
}
},
);
}
Future<void> getDistributionInformation() async {
await safeCall<KillHouseDistributionInfo?>(
call: () async => await root.chickenRepository.getIKillHouseDistributionInfo(token: root.tokenService.accessToken.value!),
onSuccess: (result) {
if (result != null) {
iLog(result);
killHouseDistributionInfo.value = result;
iLog(killHouseDistributionInfo.value);
}
},
onError: (error, stackTrace) {},
);
}
void errorHandler(DioException error) {
handleGeneric(error, () {
root.tokenService.deleteTokens();
});
}
@override
void onReady() {
super.onReady();
}
@override
void onClose() {
super.onClose();
}
}

View File

@@ -2,7 +2,6 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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/presentation/routes/routes.dart';
import 'package:rasadyar_core/core.dart';
import 'logic.dart';
@@ -70,111 +69,19 @@ class HomePage extends GetView<HomeLogic> {
SizedBox(height: 8),
_todayShipmentWidget(),
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 13),
child: Row(
spacing: 8,
children: [
Expanded(
child: _informationLabelCard(
title: 'مانده انبار',
description: '2،225،256',
iconPath: Assets.vec.cubeSearchSvg.path,
iconColor: const Color(0xFF426060),
bgDescriptionColor: const Color(0xFFC7DFE0),
bgLabelColor: const Color(0xFFA5D1D2),
),
),
Expanded(
child: _informationLabelCard(
title: 'توزیع شده',
description: '2،225،256',
iconPath: Assets.vec.cubeRotateSvg.path,
iconColor: Color(0xFF5C4D64),
bgLabelColor: Color(0xFFC8B8D1),
bgDescriptionColor: Color(0xFFDAD4DD),
),
),
],
),
),
_inventoryWidget(),
Row(
children: [Text('اطلاعات بارها', textAlign: TextAlign.right, style: AppFonts.yekan16)],
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 13),
child: Row(
spacing: 8,
children: [
Expanded(
child: _informationLabelCard(
title: 'داخل استان',
description: '2،225،256',
iconPath: Assets.vec.a3dCubeSquareSvg.path,
iconColor: const Color(0xFF6C5D60),
bgDescriptionColor: const Color(0xFFEDDCE0),
bgLabelColor: const Color(0xFFDDC0C7),
),
),
Expanded(
child: _informationLabelCard(
title: 'خارج استان',
description: '2،225،256',
iconPath: Assets.vec.cubeSearchSvg.path,
iconColor: Color(0xFF2D5FFF),
bgLabelColor: const Color(0xFFAFCBFF),
bgDescriptionColor: const Color(0xFFCEDFFF),
),
),
],
),
),
_informationShipment(),
Row(
children: [Text('اطلاعات توزیع', textAlign: TextAlign.right, style: AppFonts.yekan16)],
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 13),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 8,
children: [
Expanded(
child: _informationIconCard(
title: 'توزیع داخل استان',
description: '2،225،256',
iconPath: Assets.vec.truckSvg.path,
iconColor: const Color.fromRGBO(85, 97, 93, 1),
bgDescriptionColor: const Color(0xFFE6FAF5),
bgLabelColor: const Color(0xFFB0EFDF),
),
),
Expanded(
child: _informationIconCard(
title: 'توزیع خارج استان',
description: '2،225،256',
iconPath: Assets.vec.truckFastSvg.path,
iconColor: Color(0xFF647379),
bgDescriptionColor: const Color(0xFFEAEFFF),
bgLabelColor: const Color(0xFFD4DEFF),
),
),
Expanded(
child: _informationIconCard(
title: 'قطعه بندی',
description: '2،225،256',
iconPath: Assets.vec.convertCubeSvg.path,
iconColor: const Color(0xFF6F6164),
bgDescriptionColor: const Color(0xFFEDDCE0),
bgLabelColor: const Color(0xFFE0BCC5),
),
),
],
),
),
distributionInformationWidget(),
],
),
),
@@ -226,64 +133,190 @@ class HomePage extends GetView<HomeLogic> {
),
);
}
Container _todayShipmentWidget() {
return Container(
height: 70,
width: Get.width / 2,
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
clipBehavior: Clip.hardEdge,
child: Row(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [const Color(0xFFEAEFFF), Colors.white],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Assets.icons.cubeScan.svg(width: 30, height: 30),
Text(
'بارهای امروز',
textAlign: TextAlign.right,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
],
Widget distributionInformationWidget() {
return Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 13),
child: ObxValue((data) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 8,
children: [
Expanded(
child: _informationIconCard(
title: 'توزیع داخل استان',
isLoading: data.value == null,
description: data.value?.freeSalesWeight.toFormatted ?? '0',
iconPath: Assets.vec.truckSvg.path,
iconColor: const Color.fromRGBO(85, 97, 93, 1),
bgDescriptionColor: const Color(0xFFE6FAF5),
bgLabelColor: const Color(0xFFB0EFDF),
),
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text(
'2،225،256',
textAlign: TextAlign.right,
style: AppFonts.yekan16.copyWith(color: AppColor.textColor),
),
Text(
'کیلوگرم',
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.textColor),
),
],
Expanded(
child: _informationIconCard(
title: 'توزیع خارج استان',
isLoading: data.value == null,
description: data.value?.stewardAllocationsWeight.toFormatted ?? '0',
iconPath: Assets.vec.truckFastSvg.path,
iconColor: Color(0xFF647379),
bgDescriptionColor: const Color(0xFFEAEFFF),
bgLabelColor: const Color(0xFFD4DEFF),
),
),
),
],
),
Expanded(
child: _informationIconCard(
title: 'قطعه بندی',
description: '2،225،256',
iconPath: Assets.vec.convertCubeSvg.path,
iconColor: const Color(0xFF6F6164),
bgDescriptionColor: const Color(0xFFEDDCE0),
bgLabelColor: const Color(0xFFE0BCC5),
),
),
],
);
}, controller.killHouseDistributionInfo),
);
}
Widget _informationShipment() {
return Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 13),
child: ObxValue((data) {
return Row(
spacing: 8,
children: [
Expanded(
child: _informationLabelCard(
title: 'داخل استان',
isLoading: data.value == null,
description: data.value != null
? ((data.value?.provinceGovernmentalCarcassesWeight ?? 0) +
(data.value?.provinceFreeCarcassesWeight ?? 0))
.toFormatted
: '0',
iconPath: Assets.vec.a3dCubeSquareSvg.path,
iconColor: const Color(0xFF6C5D60),
bgDescriptionColor: const Color(0xFFEDDCE0),
bgLabelColor: const Color(0xFFDDC0C7),
),
),
Expanded(
child: _informationLabelCard(
title: 'خارج استان',
isLoading: data.value == null,
description: data.value?.freeBuyingCarcassesWeight.toFormatted ?? '0',
iconPath: Assets.vec.cubeSearchSvg.path,
iconColor: Color(0xFF2D5FFF),
bgLabelColor: const Color(0xFFAFCBFF),
bgDescriptionColor: const Color(0xFFCEDFFF),
),
),
],
);
}, controller.inventoryModel),
);
}
Widget _inventoryWidget() {
return ObxValue((data) {
return Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 13),
child: Row(
spacing: 8,
children: [
Expanded(
child: _informationLabelCard(
title: 'مانده انبار',
isLoading: data.value == null,
description: data.value?.totalRemainWeight.toFormatted ?? '0',
iconPath: Assets.vec.cubeSearchSvg.path,
iconColor: const Color(0xFF426060),
bgDescriptionColor: const Color(0xFFC7DFE0),
bgLabelColor: const Color(0xFFA5D1D2),
),
),
Expanded(
child: _informationLabelCard(
title: 'توزیع شده',
isLoading: data.value == null,
description: data.value?.realAllocatedWeight.toFormatted ?? '0',
iconPath: Assets.vec.cubeRotateSvg.path,
iconColor: Color(0xFF5C4D64),
bgLabelColor: Color(0xFFC8B8D1),
bgDescriptionColor: Color(0xFFDAD4DD),
),
),
],
),
);
}, controller.inventoryModel);
}
Widget _todayShipmentWidget() {
return ObxValue((data) {
return Container(
height: 70,
width: Get.width / 2,
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
clipBehavior: Clip.hardEdge,
child: Row(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [const Color(0xFFEAEFFF), Colors.white],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Assets.icons.cubeScan.svg(width: 30, height: 30),
Text(
'بارهای امروز',
textAlign: TextAlign.right,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
],
),
),
),
Expanded(
child: data.value == null
? CupertinoActivityIndicator()
: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text(
data.value.toFormatted,
textAlign: TextAlign.right,
style: AppFonts.yekan16.copyWith(color: AppColor.textColor),
),
Text(
'کیلوگرم',
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.textColor),
),
],
),
),
],
),
);
}, controller.totalWeightTodayBars);
}
Container _informationLabelCard({
required String title,
required String description,
String unit = 'کیلوگرم',
bool isLoading = false,
required String iconPath,
required Color iconColor,
required Color bgDescriptionColor,
@@ -326,22 +359,24 @@ class HomePage extends GetView<HomeLogic> {
color: bgDescriptionColor,
borderRadius: BorderRadius.only(topLeft: Radius.circular(8), bottomLeft: Radius.circular(8)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text(
description,
textAlign: TextAlign.right,
style: AppFonts.yekan16.copyWith(color: AppColor.mediumGreyDarkActive),
),
Text(
unit,
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.mediumGreyDarkActive),
),
],
),
child: isLoading
? Center(child: CupertinoActivityIndicator())
: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text(
description,
textAlign: TextAlign.right,
style: AppFonts.yekan16.copyWith(color: AppColor.mediumGreyDarkActive),
),
Text(
unit,
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.mediumGreyDarkActive),
),
],
),
),
),
],
@@ -353,6 +388,7 @@ class HomePage extends GetView<HomeLogic> {
required String title,
required String description,
String unit = 'کیلوگرم',
bool isLoading = false,
required String iconPath,
required Color iconColor,
required Color bgDescriptionColor,
@@ -385,11 +421,14 @@ class HomePage extends GetView<HomeLogic> {
textAlign: TextAlign.right,
style: AppFonts.yekan14.copyWith(color: AppColor.mediumGreyDarkActive),
),
Text(
description,
textAlign: TextAlign.right,
style: AppFonts.yekan16.copyWith(color: AppColor.mediumGreyDarkActive),
),
isLoading
? Center(child: CupertinoActivityIndicator())
: Text(
description,
textAlign: TextAlign.right,
style: AppFonts.yekan16.copyWith(color: AppColor.mediumGreyDarkActive),
),
Text(
unit,
textAlign: TextAlign.center,
@@ -483,7 +522,7 @@ class HomePage extends GetView<HomeLogic> {
);
}
/* Column oldPage() {
/* Column oldPage() {
return Column(
children: [
inventoryWidget(),
@@ -652,19 +691,19 @@ class HomePage extends GetView<HomeLogic> {
),
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()),
],
)
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()),
);
}