fix : di for Role
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'package:rasadyar_chicken/data/repositories/chicken/chicken_repository.da
|
||||
import 'package:rasadyar_chicken/data/repositories/chicken/chicken_repository_imp.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
GetIt diChicken = GetIt.instance;
|
||||
GetIt diChicken = GetIt.asNewInstance();
|
||||
|
||||
Future<void> setupChickenDI() async {
|
||||
diChicken.registerSingleton(DioErrorHandler());
|
||||
@@ -45,9 +45,7 @@ Future<void> setupChickenDI() async {
|
||||
final dioRemote = diChicken.get<DioRemote>();
|
||||
await dioRemote.init();
|
||||
|
||||
diChicken.registerLazySingleton<AuthRemoteDataSource>(
|
||||
() => AuthRemoteDataSourceImp(dioRemote),
|
||||
);
|
||||
diChicken.registerLazySingleton<AuthRemoteDataSource>(() => AuthRemoteDataSourceImp(dioRemote));
|
||||
|
||||
diChicken.registerLazySingleton<AuthRepository>(
|
||||
() => AuthRepositoryImpl(diChicken.get<AuthRemoteDataSource>()),
|
||||
@@ -78,7 +76,7 @@ Future<void> newSetupAuthDI(String newUrl) async {
|
||||
await diChicken.unregister<AppInterceptor>(instanceName: 'chickenInterceptor');
|
||||
}
|
||||
diChicken.registerLazySingleton<AppInterceptor>(
|
||||
() => AppInterceptor(
|
||||
() => AppInterceptor(
|
||||
refreshTokenCallback: () async => null,
|
||||
saveTokenCallback: (String newToken) async {
|
||||
await tokenService.saveAccessToken(newToken);
|
||||
@@ -96,7 +94,7 @@ Future<void> newSetupAuthDI(String newUrl) async {
|
||||
await diChicken.unregister<DioRemote>();
|
||||
}
|
||||
diChicken.registerLazySingleton<DioRemote>(
|
||||
() => DioRemote(
|
||||
() => DioRemote(
|
||||
baseUrl: newUrl,
|
||||
interceptors: diChicken.get<AppInterceptor>(instanceName: 'chickenInterceptor'),
|
||||
),
|
||||
@@ -109,10 +107,12 @@ Future<void> newSetupAuthDI(String newUrl) async {
|
||||
await reRegister<AuthRepository>(() => AuthRepositoryImpl(diChicken.get<AuthRemoteDataSource>()));
|
||||
await reRegister<ChickenRemoteDatasource>(() => ChickenRemoteDatasourceImp(dioRemote));
|
||||
await reRegister<ChickenLocalDataSource>(() => ChickenLocalDataSourceImp());
|
||||
await reRegister<ChickenRepository>(() => ChickenRepositoryImp(
|
||||
remote: diChicken.get<ChickenRemoteDatasource>(),
|
||||
local: diChicken.get<ChickenLocalDataSource>(),
|
||||
));
|
||||
await reRegister<ChickenRepository>(
|
||||
() => ChickenRepositoryImp(
|
||||
remote: diChicken.get<ChickenRemoteDatasource>(),
|
||||
local: diChicken.get<ChickenLocalDataSource>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> reRegister<T extends Object>(T Function() factory) async {
|
||||
@@ -121,8 +121,11 @@ Future<void> reRegister<T extends Object>(T Function() factory) async {
|
||||
}
|
||||
diChicken.registerLazySingleton<T>(factory);
|
||||
}
|
||||
|
||||
Future<void> removeChickenDI() async {
|
||||
if (diChicken.isRegistered<DioErrorHandler>()) {
|
||||
eLog("removeChickenDI");
|
||||
await diChicken.resetScope();
|
||||
/* if (diChicken.isRegistered<DioErrorHandler>()) {
|
||||
diChicken.unregister<DioErrorHandler>();
|
||||
}
|
||||
if (diChicken.isRegistered<AppInterceptor>(instanceName: 'chickenInterceptor')) {
|
||||
@@ -145,5 +148,5 @@ Future<void> removeChickenDI() async {
|
||||
}
|
||||
if (diChicken.isRegistered<ChickenRepository>()) {
|
||||
diChicken.unregister<ChickenRepository>();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import 'package:rasadyar_inspection/data/repositories/user/user_repository_imp.d
|
||||
import 'package:rasadyar_inspection/data/utils/dio_exception_handeler.dart';
|
||||
import 'package:rasadyar_inspection/presentation/routes/app_routes.dart';
|
||||
|
||||
GetIt diInspection = GetIt.instance;
|
||||
GetIt diInspection = GetIt.asNewInstance();
|
||||
|
||||
Future<void> setupInspectionDI() async {
|
||||
diInspection.registerSingleton(DioErrorHandler());
|
||||
@@ -71,7 +71,9 @@ Future<void> setupInspectionDI() async {
|
||||
|
||||
|
||||
Future<void> removeInspectionDI() async {
|
||||
if (diInspection.isRegistered<DioErrorHandler>()) {
|
||||
eLog("removeInspectionDI");
|
||||
await diInspection.resetScope();
|
||||
/* if (diInspection.isRegistered<DioErrorHandler>()) {
|
||||
diInspection.unregister<DioErrorHandler>();
|
||||
}
|
||||
if (diInspection.isRegistered<AppInterceptor>()) {
|
||||
@@ -100,5 +102,5 @@ Future<void> removeInspectionDI() async {
|
||||
}
|
||||
if (diInspection.isRegistered<ImagePicker>()) {
|
||||
diInspection.unregister<ImagePicker>();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ extension HiveRegistrar on HiveInterface {
|
||||
|
||||
extension IsolatedHiveRegistrar on IsolatedHiveInterface {
|
||||
void registerAdapters() {
|
||||
registerAdapter(HerdLocalAdapter());
|
||||
registerAdapter(LivestockLocalAdapter());
|
||||
registerAdapter(LivestockLocalModelAdapter());
|
||||
registerAdapter(LocationLocalAdapter());
|
||||
registerAdapter(RancherLocalAdapter());
|
||||
registerAdapter(TmpLocationsAdapter());
|
||||
registerAdapter(HerdLocalAdapter(), override: true);
|
||||
registerAdapter(LivestockLocalAdapter(), override: true);
|
||||
registerAdapter(LivestockLocalModelAdapter(), override: true);
|
||||
registerAdapter(LocationLocalAdapter(), override: true);
|
||||
registerAdapter(RancherLocalAdapter(), override: true);
|
||||
registerAdapter(TmpLocationsAdapter(), override: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/common/constant.dart';
|
||||
import 'package:rasadyar_livestock/data/common/dio_exception_handeler.dart';
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/auth/auth_remote.dart';
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/auth/auth_remote_imp.dart';
|
||||
@@ -14,10 +13,11 @@ import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
||||
|
||||
import '../data/data_source/local/tmp/tmp_local_data-source.dart';
|
||||
|
||||
GetIt get diLiveStock => GetIt.instance;
|
||||
GetIt diLiveStock= GetIt.asNewInstance();
|
||||
|
||||
Future<void> setupLiveStockDI() async {
|
||||
diLiveStock.registerSingleton(DioErrorHandler());
|
||||
|
||||
await IsolatedHive.initFlutter();
|
||||
IsolatedHive.registerAdapters();
|
||||
final tokenService = Get.find<TokenStorageService>();
|
||||
@@ -30,7 +30,7 @@ Future<void> setupLiveStockDI() async {
|
||||
diLiveStock.registerLazySingleton<AppInterceptor>(
|
||||
() => AppInterceptor(
|
||||
refreshTokenCallback: () async {
|
||||
// Use lazy access to avoid circular dependency
|
||||
// Use lazy access to avoid circular dependency
|
||||
final authRepository = diLiveStock.get<AuthRepository>();
|
||||
final hasAuthenticated = await authRepository.hasAuthenticated();
|
||||
if (hasAuthenticated) {
|
||||
@@ -95,7 +95,12 @@ Future<void> setupLiveStockDI() async {
|
||||
}
|
||||
|
||||
Future<void> removeLiveStockDI() async {
|
||||
if (diLiveStock.isRegistered<DioErrorHandler>()) {
|
||||
eLog("removeLiveStockDI");
|
||||
await diLiveStock.resetScope();
|
||||
|
||||
|
||||
|
||||
/* if (diLiveStock.isRegistered<DioErrorHandler>()) {
|
||||
diLiveStock.unregister<DioErrorHandler>();
|
||||
}
|
||||
if (diLiveStock.isRegistered<AppInterceptor>()) {
|
||||
@@ -121,5 +126,5 @@ Future<void> removeLiveStockDI() async {
|
||||
}
|
||||
if (diLiveStock.isRegistered<ImagePicker>()) {
|
||||
diLiveStock.unregister<ImagePicker>();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user