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,15 +1,14 @@
import 'package:flutter/material.dart' show Text, EdgeInsets, Colors;
import 'package:flutter/material.dart' show Colors;
import 'package:flutter/widgets.dart';
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_chicken/presentation/pages/home/view.dart';
import 'package:rasadyar_chicken/presentation/pages/sales_out_of_province/view.dart';
import 'package:rasadyar_chicken/presentation/utils/utils.dart';
import 'package:rasadyar_core/core.dart';
enum ErrorLocationType { serviceDisabled, permissionDenied, none }
@@ -24,15 +23,14 @@ class RootLogic extends GetxController {
Container(color: Colors.amber),
];
RxList<ErrorLocationType> errorLocationType = RxList();
RxMap<int, dynamic> inventoryExpandedList = RxMap();
late DioRemote dioRemote;
var tokenService = Get.find<TokenStorageService>();
late ChickenRepository chickenRepository;
late DioRemote dioRemote;
RxInt count = 5.obs;
RxList<InventoryModel> inventoryList = RxList();
Rxn<KillHouseDistributionInfo> killHouseDistributionInfo = Rxn<KillHouseDistributionInfo>();
RxList<ErrorLocationType> errorLocationType = RxList();
RxMap<int, dynamic> inventoryExpandedList = RxMap();
@override
void onInit() {
@@ -40,8 +38,9 @@ class RootLogic extends GetxController {
dioRemote = DioRemote(baseUrl: tokenService.baseurl.value);
dioRemote.init();
chickenRepository = ChickenRepositoryImpl(dioRemote);
getInventory();
getKillHouseDistributionInfo();
/*getInventory();
getKillHouseDistributionInfo();*/
}
void toggleExpanded(int index) {
@@ -52,63 +51,16 @@ class RootLogic extends GetxController {
}
}
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);
}
},
);
void rootErrorHandler(DioException error) {
handleGeneric(error, () {
tokenService.deleteTokens();
});
}
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,
);
}
void changePage(int index) {
currentPage.value = index;

View File

@@ -326,7 +326,7 @@ class RootPage extends GetView<RootLogic> {
);
}
Column oldPage() {
/*Column oldPage() {
return Column(
children: [
inventoryWidget(),
@@ -455,7 +455,7 @@ class RootPage extends GetView<RootLogic> {
),
],
);
}
}*/
Widget buildRow(String title, String value) {
return Padding(