feat : change app inspector and exception handling
This commit is contained in:
@@ -9,20 +9,19 @@ import 'package:rasadyar_core/core.dart';
|
||||
class HomeLogic extends GetxController {
|
||||
RootLogic rootLogic = Get.find<RootLogic>();
|
||||
RxnInt totalWeightTodayBars = RxnInt();
|
||||
Rxn<InventoryModel> inventoryModel = Rxn<InventoryModel>();
|
||||
Rxn<KillHouseDistributionInfo> killHouseDistributionInfo = Rxn<KillHouseDistributionInfo>();
|
||||
|
||||
RxBool isExpanded = false.obs;
|
||||
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
getTodayBars();
|
||||
getInventory();
|
||||
getDistributionInformation();
|
||||
}
|
||||
|
||||
|
||||
Future<void> getTodayBars() async {
|
||||
await safeCall<BarInformation?>(
|
||||
call: () async => await rootLogic.chickenRepository.getGeneralBarInformation(
|
||||
@@ -30,51 +29,22 @@ class HomeLogic extends GetxController {
|
||||
queryParameters: buildQueryParams(fromDate: DateTime.now(), toDate: DateTime.now()),
|
||||
),
|
||||
onSuccess: (result) {
|
||||
iLog(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 rootLogic.chickenRepository.getInventory(token: rootLogic.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 rootLogic.chickenRepository.getKillHouseDistributionInfo(token: rootLogic.tokenService.accessToken.value!),
|
||||
call: () async => await rootLogic.chickenRepository.getKillHouseDistributionInfo(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
killHouseDistributionInfo.value = result;
|
||||
@@ -85,19 +55,5 @@ class HomeLogic extends GetxController {
|
||||
}
|
||||
|
||||
|
||||
void errorHandler(DioException error) {
|
||||
handleGeneric(error, () {
|
||||
rootLogic.tokenService.deleteTokens();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ class HomePage extends GetView<HomeLogic> {
|
||||
),
|
||||
],
|
||||
);
|
||||
}, controller.inventoryModel),
|
||||
}, controller.rootLogic.inventoryModel),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ class HomePage extends GetView<HomeLogic> {
|
||||
],
|
||||
),
|
||||
);
|
||||
}, controller.inventoryModel);
|
||||
}, controller.rootLogic.inventoryModel);
|
||||
}
|
||||
|
||||
Widget _todayShipmentWidget() {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
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/di/chicken_di.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';
|
||||
@@ -39,19 +42,39 @@ class RootLogic extends GetxController {
|
||||
Rxn<InventoryModel> inventoryModel = Rxn<InventoryModel>();
|
||||
RxList<IranProvinceCityModel> provinces = <IranProvinceCityModel>[].obs;
|
||||
|
||||
// Cancel tokens for API calls
|
||||
CancelToken? _inventoryCancelToken;
|
||||
CancelToken? _provincesCancelToken;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
dioRemote = DioRemote(baseUrl: tokenService.baseurl.value);
|
||||
dioRemote.init();
|
||||
chickenRepository = ChickenRepositoryImpl(dioRemote);
|
||||
|
||||
getProvinces();
|
||||
chickenRepository = diChicken.get<ChickenRepositoryImpl>();
|
||||
|
||||
getInventory();
|
||||
//getKillHouseDistributionInfo();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
// Only call these methods if they haven't been called before
|
||||
if (provinces.isEmpty) {
|
||||
getProvinces();
|
||||
}
|
||||
if (inventoryModel.value == null) {
|
||||
getInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// Cancel any ongoing requests when controller is disposed
|
||||
_inventoryCancelToken?.cancel();
|
||||
_provincesCancelToken?.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void toggleExpanded(int index) {
|
||||
if (inventoryExpandedList.keys.contains(index)) {
|
||||
inventoryExpandedList.remove(index);
|
||||
@@ -61,24 +84,24 @@ class RootLogic extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> getInventory() async {
|
||||
// Cancel previous request if still running
|
||||
_inventoryCancelToken?.cancel();
|
||||
_inventoryCancelToken = CancelToken();
|
||||
|
||||
await safeCall<List<InventoryModel>?>(
|
||||
call: () async =>
|
||||
await chickenRepository.getInventory(token: tokenService.accessToken.value!),
|
||||
call: () async => await chickenRepository.getInventory(
|
||||
token: tokenService.accessToken.value!,
|
||||
cancelToken: _inventoryCancelToken,
|
||||
),
|
||||
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);
|
||||
if (error is DioException && error.type == DioExceptionType.cancel) {
|
||||
// Request was cancelled, ignore the error
|
||||
return;
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -95,20 +118,22 @@ class RootLogic extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> getProvinces() async {
|
||||
// Cancel previous request if still running
|
||||
_provincesCancelToken?.cancel();
|
||||
_provincesCancelToken = CancelToken();
|
||||
|
||||
try {
|
||||
final res = await chickenRepository.getProvince();
|
||||
final res = await chickenRepository.getProvince(cancelToken: _provincesCancelToken);
|
||||
if (res != null) {
|
||||
provinces.clear();
|
||||
provinces.value = res;
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) {
|
||||
// Request was cancelled, ignore the error
|
||||
return;
|
||||
}
|
||||
provinces.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void errorHandler(DioException error) {
|
||||
handleGeneric(error, () {
|
||||
tokenService.deleteTokens();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@ import 'package:rasadyar_chicken/presentation/pages/root/logic.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
class SaleLogic extends GetxController {
|
||||
Rxn<List<AllocatedMadeModel>?> allocatedMadeModel =
|
||||
Rxn<List<AllocatedMadeModel>?>();
|
||||
Rxn<List<AllocatedMadeModel>?> allocatedMadeModel = Rxn<List<AllocatedMadeModel>?>();
|
||||
RxList<ProductModel> rolesProductsModel = RxList<ProductModel>();
|
||||
|
||||
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
|
||||
|
||||
Rxn<StewardFreeBarDashboard> stewardFreeDashboard =
|
||||
Rxn<StewardFreeBarDashboard>();
|
||||
Rxn<StewardFreeBarDashboard> stewardFreeDashboard = Rxn<StewardFreeBarDashboard>();
|
||||
|
||||
RootLogic rootLogic = Get.find<RootLogic>();
|
||||
|
||||
@@ -25,6 +23,11 @@ class SaleLogic extends GetxController {
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
routesName = [...rootLogic.routesName, 'فروش'].toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
getStewardDashBord();
|
||||
getRolesProducts();
|
||||
}
|
||||
@@ -33,12 +36,7 @@ class SaleLogic extends GetxController {
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.getAllocatedMade(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
queryParameters: buildQueryParams(
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
search: 'filter',
|
||||
role: 'Steward',
|
||||
),
|
||||
queryParameters: buildQueryParams(page: 1, pageSize: 20, search: 'filter', role: 'Steward'),
|
||||
),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
@@ -81,8 +79,7 @@ class SaleLogic extends GetxController {
|
||||
safeCall(
|
||||
call: () async => await rootLogic.chickenRepository.confirmAllAllocation(
|
||||
token: rootLogic.tokenService.accessToken.value!,
|
||||
allocationTokens:
|
||||
allocatedMadeModel.value?.map((e) => e.key!).toList() ?? [],
|
||||
allocationTokens: allocatedMadeModel.value?.map((e) => e.key!).toList() ?? [],
|
||||
),
|
||||
onSuccess: (result) {
|
||||
getAllocatedMade();
|
||||
|
||||
Reference in New Issue
Block a user