chore : delete auth package because each project has different auth , must be separated auth logic
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import 'package:rasadyar_auth/auth.dart';
|
||||
|
||||
import 'package:rasadyar_chicken/data/di/chicken_di.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
@@ -6,7 +6,6 @@ final di = GetIt.instance;
|
||||
|
||||
Future<void> setupPreInjection() async {
|
||||
await setupAllCoreProvider();
|
||||
await setupAuthDI();
|
||||
di.registerSingleton<DioRemote>(
|
||||
DioRemote(baseUrl: 'https://everestacademy.ir/'),
|
||||
instanceName: 'baseRemote',
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
|
||||
import 'package:rasadyar_auth/data/models/local/module/module_model.dart';
|
||||
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/inspection.dart';
|
||||
import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
||||
|
||||
class AuthService extends GetxService {
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
RxBool accessRes = false.obs;
|
||||
RxBool refAccessRes = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
ever(tokenService.accessToken, (callback) {
|
||||
accessRes.value = (callback != null);
|
||||
});
|
||||
|
||||
ever(tokenService.refreshToken, (callback) {
|
||||
refAccessRes.value = (callback != null);
|
||||
});
|
||||
|
||||
everAll([accessRes, refAccessRes], (_) {
|
||||
if (accessRes.value && refAccessRes.value) {
|
||||
var targetPage = getTargetPage(tokenService.appModule.value);
|
||||
Get.offAllNamed(targetPage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_app/infrastructure/service/app_navigation_observer.dart';
|
||||
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
|
||||
import 'package:rasadyar_auth/auth.dart';
|
||||
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import 'infrastructure/di/di.dart';
|
||||
import 'infrastructure/service/auth_service.dart';
|
||||
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await setupPreInjection();
|
||||
|
||||
await setupPreInjection();
|
||||
Get.put(TokenStorageService());
|
||||
await Get.find<TokenStorageService>().init();
|
||||
|
||||
|
||||
Get.put(AuthMiddleware());
|
||||
Get.put(AuthService());
|
||||
runApp(MyApp());
|
||||
|
||||
// runApp(DevicePreview(builder: (context) => ForDevicePreview(),));
|
||||
|
||||
28
lib/presentation/pages/modules/logic.dart
Normal file
28
lib/presentation/pages/modules/logic.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
class ModulesLogic extends GetxController {
|
||||
|
||||
List<ModuleModel> moduleList=[
|
||||
ModuleModel(title: 'بازرسی', icon: Assets.icons.inspection.path, module: Module.inspection),
|
||||
ModuleModel(title: 'دام', icon: Assets.icons.liveStock.path, module: Module.liveStocks),
|
||||
ModuleModel(title: 'مرغ', icon: Assets.icons.liveStock.path, module: Module.chicken),
|
||||
];
|
||||
|
||||
|
||||
RxnInt selectedIndex = RxnInt(null);
|
||||
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
50
lib/presentation/pages/modules/view.dart
Normal file
50
lib/presentation/pages/modules/view.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/inspection.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
class ModulesPage extends GetView<ModulesLogic> {
|
||||
const ModulesPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('انتخاب سامانه', style: AppFonts.yekan18.copyWith(color: Colors.white)),
|
||||
centerTitle: true,
|
||||
backgroundColor: AppColor.blueNormal,
|
||||
),
|
||||
body: GridView.builder(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 20),
|
||||
|
||||
itemBuilder: (context, index) {
|
||||
final module = controller.moduleList[index];
|
||||
return CardIcon(
|
||||
title: module.title,
|
||||
icon: module.icon,
|
||||
onTap: () {
|
||||
controller.selectedIndex.value = index;
|
||||
switch (module.module) {
|
||||
case Module.inspection:
|
||||
Get.toNamed(InspectionRoutes.init);
|
||||
break;
|
||||
case Module.liveStocks:
|
||||
case Module.chicken:
|
||||
Get.toNamed(InspectionRoutes.init);
|
||||
break;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
),
|
||||
physics: BouncingScrollPhysics(),
|
||||
itemCount: controller.moduleList.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:rasadyar_app/data/model/app_info_model.dart';
|
||||
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
|
||||
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/inspection.dart';
|
||||
import 'package:rasadyar_inspection/presentation/routes/app_routes.dart';
|
||||
|
||||
class SplashLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
late final AnimationController scaleController;
|
||||
@@ -158,7 +155,7 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
|
||||
final module = tokenService.appModule.value;
|
||||
final target = getTargetPage(module);
|
||||
Get.offAndToNamed(InspectionRoutes.init);
|
||||
Get.offAndToNamed(target);
|
||||
} catch (e, st) {
|
||||
debugPrint("onReady error: $e\n$st");
|
||||
}
|
||||
@@ -227,7 +224,6 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
|
||||
if (success) {
|
||||
_updateFilePath.value = filePath;
|
||||
|
||||
}
|
||||
|
||||
onUpdateDownload.value = false;
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import 'package:rasadyar_app/presentation/pages/splash/logic.dart';
|
||||
import 'package:rasadyar_app/presentation/pages/splash/view.dart';
|
||||
import 'package:rasadyar_app/presentation/pages/system_design/system_design.dart';
|
||||
import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart';
|
||||
import 'package:rasadyar_auth/presentation/routes/pages.dart';
|
||||
import 'package:rasadyar_chicken/chicken.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/inspection.dart';
|
||||
import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
||||
|
||||
|
||||
part 'app_paths.dart';
|
||||
|
||||
sealed class AppPages {
|
||||
@@ -26,7 +23,7 @@ sealed class AppPages {
|
||||
),
|
||||
|
||||
...InspectionPages.pages,
|
||||
...AuthPages.pages,
|
||||
|
||||
...LiveStockPages.pages,
|
||||
...ChickenPages.pages,
|
||||
];
|
||||
@@ -41,6 +38,6 @@ String getTargetPage(Module? value) {
|
||||
case Module.chicken:
|
||||
return ChickenRoutes.init;
|
||||
default:
|
||||
return InspectionRoutes.init;
|
||||
return AppPaths.moduleList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,6 @@ sealed class AppPaths {
|
||||
AppPaths._();
|
||||
|
||||
static const String splash = '/splash';
|
||||
static const String moduleList = '/moduleList';
|
||||
static const String systemDesignPage = '/systemDesignPage';
|
||||
}
|
||||
|
||||
24
lib/presentation/routes/auth_route_resolver_impl.dart
Normal file
24
lib/presentation/routes/auth_route_resolver_impl.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
|
||||
import 'package:rasadyar_chicken/presentation/routes/routes.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/inspection.dart';
|
||||
import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
||||
|
||||
class AppAuthRouteResolver implements AuthRouteResolver {
|
||||
@override
|
||||
String getAuthRouteForModule(Module module) {
|
||||
switch (module) {
|
||||
case Module.inspection:
|
||||
return InspectionRoutes.auth;
|
||||
case Module.liveStocks:
|
||||
return LiveStockRoutes.auth;
|
||||
case Module.chicken:
|
||||
return ChickenRoutes.auth;
|
||||
default:
|
||||
throw UnimplementedError('No auth route for module: $module');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String getFallbackRoute() => AppPaths.moduleList;
|
||||
}
|
||||
Reference in New Issue
Block a user