fix : sale in the province

This commit is contained in:
2025-06-28 13:12:17 +03:30
parent 7bb19a7ffc
commit 9a098acf00
5 changed files with 519 additions and 482 deletions

View File

@@ -1,6 +1,8 @@
import 'package:flutter/material.dart' show Colors;
import 'package:flutter/widgets.dart';
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
import 'package:rasadyar_auth/data/utils/safe_call.dart';
import 'package:rasadyar_chicken/data/models/response/inventory/inventory_model.dart';
import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_province_city_model.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository_imp.dart';
@@ -22,15 +24,13 @@ class RootLogic extends GetxController {
Container(color: Colors.amber),
];
late DioRemote dioRemote;
var tokenService = Get.find<TokenStorageService>();
late ChickenRepository chickenRepository;
RxList<ErrorLocationType> errorLocationType = RxList();
RxMap<int, dynamic> inventoryExpandedList = RxMap();
Rxn<InventoryModel> inventoryModel = Rxn<InventoryModel>();
RxList<IranProvinceCityModel> provinces = <IranProvinceCityModel>[].obs;
@override
@@ -42,8 +42,8 @@ class RootLogic extends GetxController {
getProvinces();
/*getInventory();
getKillHouseDistributionInfo();*/
getInventory();
//getKillHouseDistributionInfo();
}
void toggleExpanded(int index) {
@@ -54,6 +54,29 @@ 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) {
inventoryModel.value = result.first;
}
},
onError: (error, stackTrace) {
switch (error.response?.statusCode) {
case 401:
errorHandler(error);
break;
case 403:
errorHandler(error);
break;
default:
errorHandler(error);
}
},
);
}
void rootErrorHandler(DioException error) {
handleGeneric(error, () {
tokenService.deleteTokens();
@@ -75,4 +98,10 @@ class RootLogic extends GetxController {
provinces.clear();
}
}
void errorHandler(DioException error) {
handleGeneric(error, () {
tokenService.deleteTokens();
});
}
}