fix : di for Role

This commit is contained in:
2025-09-03 11:43:52 +03:30
parent ebec27b630
commit 8e9768daf6
9 changed files with 74 additions and 86 deletions

View File

@@ -3,7 +3,6 @@ import 'package:rasadyar_chicken/data/di/chicken_di.dart';
import 'package:rasadyar_chicken/presentation/routes/routes.dart';
import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_core/data/model/local/target_page/target_page.dart';
import 'package:rasadyar_core/hive_registrar.g.dart';
import 'package:rasadyar_inspection/injection/inspection_di.dart';
import 'package:rasadyar_inspection/inspection.dart';
import 'package:rasadyar_livestock/injection/live_stock_di.dart';
@@ -13,20 +12,20 @@ class LocalStorageService extends GetxService {
static const String _targetPageBox = 'targetPageBox';
final HiveLocalStorage _localStorage = diCore.get<HiveLocalStorage>();
late Box<TargetPage> _targetBox;
Future<void> init() async {
Hive.registerAdapters();
await _localStorage.init();
await _localStorage.openBox<TargetPage>(_targetPageBox);
seedTargetPage();
}
Future<void> seedTargetPage() async {
var existing = getTargetPage(null);
if (existing == null) {
_localStorage.addAll(
_localStorage.addAll<TargetPage>(
boxName: _targetPageBox,
values: [
values: <TargetPage>[
TargetPage(
route: InspectionRoutes.init,
module: Module.inspection,
@@ -59,24 +58,18 @@ class LocalStorageService extends GetxService {
await _localStorage.add(boxName: _targetPageBox, value: targetPage);
}
Iterable<Future?>? getFunctionsList(List<String>? functions) {
return functions?.map((e) => getFunctionByName(e));
Iterable<Future>? getFunctionsList(List<String>? functions) {
return functions?.map((e) async => getFunctionByName(e));
}
Future? getFunctionByName(String? name) {
switch (name) {
case "setupInspectionDI":
return setupInspectionDI();
case "removeInspectionDI":
return removeInspectionDI();
case "setupLiveStockDI":
return setupLiveStockDI();
case "removeLiveStockDI":
return removeLiveStockDI();
case "setupChickenDI":
return setupChickenDI();
case "removeChickenDI":
return removeChickenDI();
default:
return null;
}

View File

@@ -12,8 +12,9 @@ Future<void> main() async {
await Hive.initFlutter();
await setupPreInjection();
Get.put(TokenStorageService());
Get.put(LocalStorageService());
await Get.find<TokenStorageService>().init();
Get.put(LocalStorageService());
await Get.find<LocalStorageService>().init();
Get.put<AuthRouteResolver>(AppAuthRouteResolver());
Get.put(AuthMiddleware());

View File

@@ -89,7 +89,7 @@ class ModulesLogic extends GetxController {
selectedIndex.value = index;
await Future.delayed(Duration(milliseconds: 300));
selectedIndex.value = null;
saveModule(module);
// saveModule(module);
await navigateToModule(module);
}
@@ -98,14 +98,14 @@ class ModulesLogic extends GetxController {
if (target.value?[0] != null) {
isLoading.value = !isLoading.value;
await target.value?[0];
await target.value?[0]?.call();
isLoading.value = !isLoading.value;
}
await Get.toNamed(target.key, arguments: module);
if (target.value?[1] != null) {
await target.value?[1];
await target.value?[1]?.call();
}
}

View File

@@ -87,26 +87,25 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
children: [
const Text('در حال دانلود بروزرسانی برنامه...'),
Obx(
() =>
Row(
spacing: 8,
children: [
Expanded(
child: LinearProgressIndicator(
value: percent.value,
color: AppColor.greenNormal,
minHeight: 4,
),
),
SizedBox(
width: 55.w,
child: Text(
'${(percent.value * 100).toStringAsFixed(2)}%',
textAlign: TextAlign.center,
),
),
],
() => Row(
spacing: 8,
children: [
Expanded(
child: LinearProgressIndicator(
value: percent.value,
color: AppColor.greenNormal,
minHeight: 4,
),
),
SizedBox(
width: 55.w,
child: Text(
'${(percent.value * 100).toStringAsFixed(2)}%',
textAlign: TextAlign.center,
),
),
],
),
),
Row(
@@ -119,9 +118,9 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
height: 40.h,
onPressed: data.value != null
? () {
installApk();
Get.back();
}
installApk();
Get.back();
}
: null,
text: 'نصب',
);
@@ -163,10 +162,7 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
await Future.wait(funs ?? []);
Get.offAndToNamed(target.route!);
}
} catch (e, st) {
debugPrint("onReady error: $e\n$st");
}

View File

@@ -44,32 +44,20 @@ sealed class AppPages {
];
}
Map<String, Future<void>?> getTargetModule(Module? value) {
switch (value) {
case Module.inspection:
return {InspectionRoutes.init: setupInspectionDI()};
case Module.liveStocks:
return {LiveStockRoutes.init: setupLiveStockDI()};
case Module.chicken:
return {ChickenRoutes.initSteward: setupChickenDI()};
default:
return {AppPaths.moduleList: null};
}
}
Map<String, List<Future<void>?>?> getAuthTargetPage(Module? value) {
Map<String, List<Future<void> Function()?>?> getAuthTargetPage(Module? value) {
switch (value) {
case Module.inspection:
return {
InspectionRoutes.auth: [setupInspectionDI(), removeInspectionDI()],
InspectionRoutes.auth: [setupInspectionDI, removeInspectionDI],
};
case Module.liveStocks:
return {
LiveStockRoutes.auth: [setupLiveStockDI(), removeLiveStockDI()],
LiveStockRoutes.auth: [setupLiveStockDI, removeLiveStockDI],
};
case Module.chicken:
return {
ChickenRoutes.auth: [setupChickenDI(), removeChickenDI()],
ChickenRoutes.auth: [setupChickenDI, removeChickenDI],
};
default:
return {AppPaths.moduleList: null};