1 - multi module in Auth select save selected module
 2 - add flutter gen for assets builder
This commit is contained in:
2025-05-19 16:16:33 +03:30
parent 982329a3eb
commit 905e407ccd
46 changed files with 1431 additions and 407 deletions

View File

@@ -5,3 +5,4 @@ library;
export 'data/services/auth_middelware.dart';
export 'data/di/auth_di.dart';
export 'data/models/local/module/module_model.dart';

View File

@@ -11,6 +11,7 @@ GetIt diAuth = GetIt.instance;
Future<void> setupAuthDI() async {
diAuth.registerLazySingleton(() => DioRemoteManager());
final manager = diAuth.get<DioRemoteManager>();
final dioRemote = await manager.setEnvironment(ApiEnvironment.dam);
diAuth.registerCachedFactory<AuthRepositoryImpl>(

View File

@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart';
import 'package:rasadyar_core/core.dart';
part 'module_model.freezed.dart';
@freezed
abstract class ModuleModel with _$ModuleModel{
const factory ModuleModel({
required String title,
required String icon,
required Module module,
}) = _ModuleModel;
}

View File

@@ -0,0 +1,148 @@
// dart format width=80
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'module_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$ModuleModel {
String get title; String get icon; Module get module;
/// Create a copy of ModuleModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ModuleModelCopyWith<ModuleModel> get copyWith => _$ModuleModelCopyWithImpl<ModuleModel>(this as ModuleModel, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ModuleModel&&(identical(other.title, title) || other.title == title)&&(identical(other.icon, icon) || other.icon == icon)&&(identical(other.module, module) || other.module == module));
}
@override
int get hashCode => Object.hash(runtimeType,title,icon,module);
@override
String toString() {
return 'ModuleModel(title: $title, icon: $icon, module: $module)';
}
}
/// @nodoc
abstract mixin class $ModuleModelCopyWith<$Res> {
factory $ModuleModelCopyWith(ModuleModel value, $Res Function(ModuleModel) _then) = _$ModuleModelCopyWithImpl;
@useResult
$Res call({
String title, String icon, Module module
});
}
/// @nodoc
class _$ModuleModelCopyWithImpl<$Res>
implements $ModuleModelCopyWith<$Res> {
_$ModuleModelCopyWithImpl(this._self, this._then);
final ModuleModel _self;
final $Res Function(ModuleModel) _then;
/// Create a copy of ModuleModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? title = null,Object? icon = null,Object? module = null,}) {
return _then(_self.copyWith(
title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
as String,icon: null == icon ? _self.icon : icon // ignore: cast_nullable_to_non_nullable
as String,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable
as Module,
));
}
}
/// @nodoc
class _ModuleModel implements ModuleModel {
const _ModuleModel({required this.title, required this.icon, required this.module});
@override final String title;
@override final String icon;
@override final Module module;
/// Create a copy of ModuleModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ModuleModelCopyWith<_ModuleModel> get copyWith => __$ModuleModelCopyWithImpl<_ModuleModel>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ModuleModel&&(identical(other.title, title) || other.title == title)&&(identical(other.icon, icon) || other.icon == icon)&&(identical(other.module, module) || other.module == module));
}
@override
int get hashCode => Object.hash(runtimeType,title,icon,module);
@override
String toString() {
return 'ModuleModel(title: $title, icon: $icon, module: $module)';
}
}
/// @nodoc
abstract mixin class _$ModuleModelCopyWith<$Res> implements $ModuleModelCopyWith<$Res> {
factory _$ModuleModelCopyWith(_ModuleModel value, $Res Function(_ModuleModel) _then) = __$ModuleModelCopyWithImpl;
@override @useResult
$Res call({
String title, String icon, Module module
});
}
/// @nodoc
class __$ModuleModelCopyWithImpl<$Res>
implements _$ModuleModelCopyWith<$Res> {
__$ModuleModelCopyWithImpl(this._self, this._then);
final _ModuleModel _self;
final $Res Function(_ModuleModel) _then;
/// Create a copy of ModuleModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? title = null,Object? icon = null,Object? module = null,}) {
return _then(_ModuleModel(
title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
as String,icon: null == icon ? _self.icon : icon // ignore: cast_nullable_to_non_nullable
as String,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable
as Module,
));
}
}
// dart format on

View File

@@ -1,3 +1,4 @@
import 'package:rasadyar_auth/auth.dart';
import 'package:rasadyar_core/core.dart';
part 'user_local_model.g.dart';
@@ -15,12 +16,16 @@ class UserLocalModel extends HiveObject {
@HiveField(4)
String? name;
@HiveField(5)
Module? module;
UserLocalModel({
this.username,
this.password,
this.token,
this.refreshToken,
this.name,
this.module,
});
UserLocalModel copyWith({
@@ -29,6 +34,7 @@ class UserLocalModel extends HiveObject {
String? token,
String? refreshToken,
String? name,
Module? module,
}) {
return UserLocalModel(
username: username ?? this.username,
@@ -36,6 +42,15 @@ class UserLocalModel extends HiveObject {
token: token ?? this.token,
refreshToken: refreshToken ?? this.refreshToken,
name: name ?? this.name,
module: module ?? this.module,
);
}
}
@HiveType(typeId: 1)
enum Module {
@HiveField(0)
liveStocks,
@HiveField(1)
inspection,
}

View File

@@ -22,13 +22,14 @@ class UserLocalModelAdapter extends TypeAdapter<UserLocalModel> {
token: fields[2] as String?,
refreshToken: fields[3] as String?,
name: fields[4] as String?,
module: fields[5] as Module?,
);
}
@override
void write(BinaryWriter writer, UserLocalModel obj) {
writer
..writeByte(5)
..writeByte(6)
..writeByte(0)
..write(obj.username)
..writeByte(1)
@@ -38,7 +39,9 @@ class UserLocalModelAdapter extends TypeAdapter<UserLocalModel> {
..writeByte(3)
..write(obj.refreshToken)
..writeByte(4)
..write(obj.name);
..write(obj.name)
..writeByte(5)
..write(obj.module);
}
@override
@@ -51,3 +54,40 @@ class UserLocalModelAdapter extends TypeAdapter<UserLocalModel> {
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class ModuleAdapter extends TypeAdapter<Module> {
@override
final typeId = 1;
@override
Module read(BinaryReader reader) {
switch (reader.readByte()) {
case 0:
return Module.liveStocks;
case 1:
return Module.inspection;
default:
return Module.liveStocks;
}
}
@override
void write(BinaryWriter writer, Module obj) {
switch (obj) {
case Module.liveStocks:
writer.writeByte(0);
case Module.inspection:
writer.writeByte(1);
}
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ModuleAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@@ -1,20 +1,26 @@
import 'dart:convert';
import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart';
import 'package:rasadyar_auth/hive_registrar.g.dart';
import 'package:rasadyar_core/core.dart';
class TokenStorageService extends GetxService {
static const String _boxName = 'secureBox';
static const String _accessTokenKey = 'accessToken';
static const String _refreshTokenKey = 'refreshToken';
static const String _moduleKey = 'moduleSelected';
final FlutterSecureStorage _secureStorage = FlutterSecureStorage();
final HiveLocalStorage _localStorage = diCore.get<HiveLocalStorage>();
RxnString accessToken = RxnString();
RxnString refreshToken = RxnString();
RxnString tsss = RxnString();
RxnString accessToken = RxnString();
RxnString refreshToken = RxnString();
Rxn<Module> appModule = Rxn(null);
Future<void> init() async {
Hive.registerAdapters();
IsolatedHive.registerAdapters();
final String? encryptedKey = await _secureStorage.read(key: 'hive_enc_key');
final encryptionKey =
encryptedKey != null
@@ -42,6 +48,10 @@ class TokenStorageService extends GetxService {
boxName: _boxName,
key: _refreshTokenKey,
);
appModule.value = _localStorage.read<Module?>(
boxName: _boxName,
key: _moduleKey,
);
}
Future<void> saveAccessToken(String token) async {
@@ -64,6 +74,12 @@ class TokenStorageService extends GetxService {
refreshToken.refresh();
}
Future<void> saveModule(Module input) async {
await _localStorage.save(boxName: _boxName, key: _moduleKey, value: input);
appModule.value = input;
appModule.refresh();
}
Future<void> deleteTokens() async {
await _localStorage.clear(_boxName);
accessToken.value = null;

View File

@@ -7,12 +7,14 @@ import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart
extension HiveRegistrar on HiveInterface {
void registerAdapters() {
registerAdapter(ModuleAdapter());
registerAdapter(UserLocalModelAdapter());
}
}
extension IsolatedHiveRegistrar on IsolatedHiveInterface {
void registerAdapters() {
registerAdapter(ModuleAdapter());
registerAdapter(UserLocalModelAdapter());
}
}

View File

@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:rasadyar_auth/auth.dart';
import 'package:rasadyar_auth/data/common/dio_error_handler.dart';
import 'package:rasadyar_auth/data/models/local/module/module_model.dart';
import 'package:rasadyar_auth/data/models/request/login_request/login_request_model.dart';
import 'package:rasadyar_auth/data/models/response/auth/auth_response_model.dart';
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
@@ -10,6 +11,8 @@ import 'package:rasadyar_auth/data/services/token_storage_service.dart';
import 'package:rasadyar_auth/presentation/widget/captcha/logic.dart';
import 'package:rasadyar_core/core.dart';
import '../../../data/models/local/user_local/user_local_model.dart';
enum AuthType { useAndPass, otp }
enum AuthStatus { init }
@@ -42,6 +45,8 @@ class AuthLogic extends GetxController {
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
final Module _module = Get.arguments;
void startTimer() {
_timer?.cancel();
secondsRemaining.value = 120;
@@ -73,8 +78,8 @@ class AuthLogic extends GetxController {
@override
void onReady() {
// TODO: implement onReady
super.onReady();
iLog('module111 : ${_module.toString()}');
}
@override
@@ -106,14 +111,16 @@ class AuthLogic extends GetxController {
Future<void> submitLoginForm() async {
if (!_isFormValid()) return;
iLog('module222 : ${_module.toString()}');
final loginRequestModel = _buildLoginRequest();
isLoading.value = true;
await safeCall<AuthResponseModel?>(
call: () => authRepository.login(authRequest: loginRequestModel.toJson()),
onSuccess: (result) async {
await tokenStorageService.saveRefreshToken(result!.refresh!);
await tokenStorageService.saveAccessToken(result!.access!);
await tokenStorageService.saveModule(_module);
await tokenStorageService.saveRefreshToken(result?.refresh ?? '');
await tokenStorageService.saveAccessToken(result?.access ?? '');
//Get.offAndToNamed(Routes.home);
},
onError: (error, stackTrace) {

View File

@@ -109,7 +109,10 @@ class AuthPage extends GetView<AuthLogic> {
},
prefixIcon: Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 6, 8),
child: vecWidget(Assets.vecCallSvg),
child: Assets.vec.callSvg.svg(
width: 12,
height: 12,
),
),
suffixIcon:
phoneController.value.text
@@ -168,7 +171,10 @@ class AuthPage extends GetView<AuthLogic> {
labelStyle: AppFonts.yekan13,
prefixIcon: Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 8, 8),
child: vecWidget(Assets.vecKeySvg),
child: Assets.vec.keySvg.svg(
width: 12,
height: 12,
),
),
boxConstraints: const BoxConstraints(
maxHeight: 34,

View File

@@ -1,7 +1,16 @@
import 'package:rasadyar_auth/data/models/local/module/module_model.dart';
import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart';
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),
];
RxnInt selectedIndex = RxnInt(null);
@override
@@ -9,6 +18,9 @@ class ModulesLogic extends GetxController {
super.onReady();
}
@override
void onClose() {
super.onClose();

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rasadyar_auth/presentation/routes/pages.dart';
import 'package:rasadyar_core/core.dart';
import 'logic.dart';
@@ -8,8 +9,37 @@ class ModulesPage extends GetView<ModulesLogic> {
@override
Widget build(BuildContext context) {
final ModulesLogic logic = Get.put(ModulesLogic());
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),
return Container();
itemBuilder: (context, index) {
final module = controller.moduleList[index];
return CardIcon(
title: module.title,
icon: module.icon,
onTap: () {
controller.selectedIndex.value = index;
Get.toNamed(AuthPaths.auth, arguments: module.module);
},
);
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
),
physics: BouncingScrollPhysics(),
itemCount: controller.moduleList.length,
),
);
}
}

View File

@@ -1,3 +1,5 @@
import 'package:rasadyar_auth/presentation/pages/modules/logic.dart';
import 'package:rasadyar_auth/presentation/pages/modules/view.dart';
import 'package:rasadyar_auth/presentation/widget/captcha/logic.dart';
import 'package:rasadyar_core/core.dart';
@@ -12,10 +14,9 @@ sealed class AuthPages {
static List<GetPage> pages = [
GetPage(
name: AuthPaths.moduleList,
page: () => AuthPage(),
page: () => ModulesPage(),
binding: BindingsBuilder(() {
Get.lazyPut(() => AuthLogic());
Get.lazyPut(() => CaptchaWidgetLogic());
Get.lazyPut(() => ModulesLogic());
}),
),

View File

@@ -9,7 +9,10 @@ class LogoWidget extends StatelessWidget {
return Column(
children: [
Row(),
Image.asset(Assets.imagesInnerSplash, width: 120, height: 120),
Assets.images.innerSplash.image(
width: 150,
height: 150,
),
Text(
'سامانه رصدیار',
style: AppFonts.yekan16.copyWith(color: AppColor.darkGreyNormal),