feat : auth package

This commit is contained in:
2025-05-11 11:49:51 +03:30
parent 8cc4a7517c
commit 9ec761e6eb
34 changed files with 665 additions and 475 deletions

View File

@@ -0,0 +1,23 @@
import 'package:auth/src/domain/entity/auth_response_entity.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'auth_response_dto.freezed.dart';
part 'auth_response_dto.g.dart';
@freezed
abstract class AuthResponseDto with _$AuthResponseDto {
const factory AuthResponseDto({
String? refresh,
String? access,
@JsonKey(name: 'otp_status') bool? otpStatus,
}) = _AuthResponseDto;
factory AuthResponseDto.fromJson(Map<String, dynamic> json) =>
_$AuthResponseDtoFromJson(json);
AuthResponseEntity toEntity() => AuthResponseEntity(
access: access,
otpStatus: otpStatus,
refresh: refresh,
);
}

View File

@@ -0,0 +1,21 @@
import 'package:rasadyar_core/core.dart';
part 'login_request_model.freezed.dart';
part 'login_request_model.g.dart';
@freezed
abstract class LoginRequestModel with _$LoginRequestModel {
const factory LoginRequestModel({
required String username,
required String password,
required String captchaCode,
required String captchaKey,
}) = _LoginRequestModel;
factory LoginRequestModel.fromJson(Map<String, dynamic> json) =>
_$LoginRequestModelFromJson(json);
const LoginRequestModel._();
String get formattedCaptchaKey => 'rest_captcha_$captchaKey.0';
}

View File

@@ -0,0 +1,157 @@
// 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 'login_request_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$LoginRequestModel {
String get username; String get password; String get captchaCode; String get captchaKey;
/// Create a copy of LoginRequestModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$LoginRequestModelCopyWith<LoginRequestModel> get copyWith => _$LoginRequestModelCopyWithImpl<LoginRequestModel>(this as LoginRequestModel, _$identity);
/// Serializes this LoginRequestModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is LoginRequestModel&&(identical(other.username, username) || other.username == username)&&(identical(other.password, password) || other.password == password)&&(identical(other.captchaCode, captchaCode) || other.captchaCode == captchaCode)&&(identical(other.captchaKey, captchaKey) || other.captchaKey == captchaKey));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,username,password,captchaCode,captchaKey);
@override
String toString() {
return 'LoginRequestModel(username: $username, password: $password, captchaCode: $captchaCode, captchaKey: $captchaKey)';
}
}
/// @nodoc
abstract mixin class $LoginRequestModelCopyWith<$Res> {
factory $LoginRequestModelCopyWith(LoginRequestModel value, $Res Function(LoginRequestModel) _then) = _$LoginRequestModelCopyWithImpl;
@useResult
$Res call({
String username, String password, String captchaCode, String captchaKey
});
}
/// @nodoc
class _$LoginRequestModelCopyWithImpl<$Res>
implements $LoginRequestModelCopyWith<$Res> {
_$LoginRequestModelCopyWithImpl(this._self, this._then);
final LoginRequestModel _self;
final $Res Function(LoginRequestModel) _then;
/// Create a copy of LoginRequestModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? username = null,Object? password = null,Object? captchaCode = null,Object? captchaKey = null,}) {
return _then(_self.copyWith(
username: null == username ? _self.username : username // ignore: cast_nullable_to_non_nullable
as String,password: null == password ? _self.password : password // ignore: cast_nullable_to_non_nullable
as String,captchaCode: null == captchaCode ? _self.captchaCode : captchaCode // ignore: cast_nullable_to_non_nullable
as String,captchaKey: null == captchaKey ? _self.captchaKey : captchaKey // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
@JsonSerializable()
class _LoginRequestModel extends LoginRequestModel {
const _LoginRequestModel({required this.username, required this.password, required this.captchaCode, required this.captchaKey}): super._();
factory _LoginRequestModel.fromJson(Map<String, dynamic> json) => _$LoginRequestModelFromJson(json);
@override final String username;
@override final String password;
@override final String captchaCode;
@override final String captchaKey;
/// Create a copy of LoginRequestModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$LoginRequestModelCopyWith<_LoginRequestModel> get copyWith => __$LoginRequestModelCopyWithImpl<_LoginRequestModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$LoginRequestModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _LoginRequestModel&&(identical(other.username, username) || other.username == username)&&(identical(other.password, password) || other.password == password)&&(identical(other.captchaCode, captchaCode) || other.captchaCode == captchaCode)&&(identical(other.captchaKey, captchaKey) || other.captchaKey == captchaKey));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,username,password,captchaCode,captchaKey);
@override
String toString() {
return 'LoginRequestModel(username: $username, password: $password, captchaCode: $captchaCode, captchaKey: $captchaKey)';
}
}
/// @nodoc
abstract mixin class _$LoginRequestModelCopyWith<$Res> implements $LoginRequestModelCopyWith<$Res> {
factory _$LoginRequestModelCopyWith(_LoginRequestModel value, $Res Function(_LoginRequestModel) _then) = __$LoginRequestModelCopyWithImpl;
@override @useResult
$Res call({
String username, String password, String captchaCode, String captchaKey
});
}
/// @nodoc
class __$LoginRequestModelCopyWithImpl<$Res>
implements _$LoginRequestModelCopyWith<$Res> {
__$LoginRequestModelCopyWithImpl(this._self, this._then);
final _LoginRequestModel _self;
final $Res Function(_LoginRequestModel) _then;
/// Create a copy of LoginRequestModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? username = null,Object? password = null,Object? captchaCode = null,Object? captchaKey = null,}) {
return _then(_LoginRequestModel(
username: null == username ? _self.username : username // ignore: cast_nullable_to_non_nullable
as String,password: null == password ? _self.password : password // ignore: cast_nullable_to_non_nullable
as String,captchaCode: null == captchaCode ? _self.captchaCode : captchaCode // ignore: cast_nullable_to_non_nullable
as String,captchaKey: null == captchaKey ? _self.captchaKey : captchaKey // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View File

@@ -0,0 +1,23 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'login_request_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_LoginRequestModel _$LoginRequestModelFromJson(Map<String, dynamic> json) =>
_LoginRequestModel(
username: json['username'] as String,
password: json['password'] as String,
captchaCode: json['captchaCode'] as String,
captchaKey: json['captchaKey'] as String,
);
Map<String, dynamic> _$LoginRequestModelToJson(_LoginRequestModel instance) =>
<String, dynamic>{
'username': instance.username,
'password': instance.password,
'captchaCode': instance.captchaCode,
'captchaKey': instance.captchaKey,
};

View File

@@ -0,0 +1,41 @@
import 'package:rasadyar_core/core.dart';
part 'user_local_model.g.dart';
@HiveType(typeId: 0)
class UserLocalModel extends HiveObject {
@HiveField(0)
String? username;
@HiveField(1)
String? password;
@HiveField(2)
String? token;
@HiveField(3)
String? refreshToken;
@HiveField(4)
String? name;
UserLocalModel({
this.username,
this.password,
this.token,
this.refreshToken,
this.name,
});
UserLocalModel copyWith({
String? username,
String? password,
String? token,
String? refreshToken,
String? name,
}) {
return UserLocalModel(
username: username ?? this.username,
password: password ?? this.password,
token: token ?? this.token,
refreshToken: refreshToken ?? this.refreshToken,
name: name ?? this.name,
);
}
}

View File

@@ -0,0 +1,12 @@
class AuthResponseEntity {
final String? access;
final String? refresh;
final bool? otpStatus;
AuthResponseEntity({this.access, this.refresh, this.otpStatus});
@override
String toString() {
return 'AuthResponseEntity{accessToken: $access, refreshToken: $refresh, expiresIn: $otpStatus}';
}
}

View File

@@ -0,0 +1,7 @@
import 'package:auth/src/domain/entity/auth_response_entity.dart';
abstract class AuthRepository {
Future<AuthResponseEntity> signIn({
required Map<String, dynamic> authRequest,
});
}

View File

@@ -9,7 +9,7 @@ enum AuthStatus { init }
enum OtpStatus { init, sent, verified, reSend }
class AuthWithUseAndPassLogic extends GetxController {
class AuthLogic extends GetxController {
Rx<GlobalKey<FormState>> formKey = GlobalKey<FormState>().obs;
Rx<GlobalKey<FormState>> formKeyOtp = GlobalKey<FormState>().obs;
Rx<GlobalKey<FormState>> formKeySentOtp = GlobalKey<FormState>().obs;

View File

@@ -5,8 +5,10 @@ import 'package:rasadyar_core/core.dart';
import 'logic.dart';
class AuthWithUseAndPassPage extends GetView<AuthWithUseAndPassLogic> {
const AuthWithUseAndPassPage({super.key});
class AuthPage extends GetView<AuthLogic> {
const AuthPage({super.key});
@override
Widget build(BuildContext context) {

View File

@@ -1,68 +0,0 @@
import 'package:flutter/animation.dart';
import 'package:get/get.dart';
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
import 'package:inspection/inspection.dart';
class SplashLogic extends GetxController with GetTickerProviderStateMixin {
late final AnimationController scaleController;
late final AnimationController rotateController;
Rxn<Animation<double>> scaleAnimation = Rxn();
Rxn<Animation<double>> rotationAnimation = Rxn();
@override
void onInit() {
super.onInit();
scaleController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1500),
);
rotateController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 8000),
);
scaleAnimation.value = Tween<double>(
begin: 0.8,
end: 1.2,
).animate(scaleController);
rotationAnimation.value = Tween<double>(
begin: 0.0,
end: 1,
).animate(rotateController);
rotateController.forward();
rotateController.addStatusListener((status) {
if (status == AnimationStatus.completed) {
rotateController.repeat();
} else if (status == AnimationStatus.dismissed) {
rotateController.forward();
}
});
scaleController.forward();
scaleController.addStatusListener((status) {
if (status == AnimationStatus.completed) {
scaleController.reverse();
} else if (status == AnimationStatus.dismissed) {
scaleController.forward();
}
});
}
@override
void onReady() {
super.onReady();
Future.delayed(const Duration(seconds: 1), () {
Get.offAllNamed(InspectionRoutes.inspection);
});
}
@override
void onClose() {
rotateController.dispose();
scaleController.dispose();
super.onClose();
}
}

View File

@@ -1,47 +0,0 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
import 'logic.dart';
class SplashPage extends GetView<SplashLogic> {
const SplashPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColor.blueDarker,
body: Center(
child: Stack(
alignment: Alignment.center,
children: [
ObxValue((data) {
return ScaleTransition(
scale: data.value!,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 1),
child: Image.asset(
Assets.imagesInnerSplash,
width: 190,
height: 190,
),
),
);
}, controller.scaleAnimation),
ObxValue((data) {
return RotationTransition(
turns: data.value!,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 1),
child: Image.asset(Assets.imagesOutterSplash),
),
);
}, controller.rotationAnimation),
],
),
),
);
}
}

View File

@@ -1,255 +0,0 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
class SystemDesignPage extends StatefulWidget {
const SystemDesignPage({super.key});
@override
State<SystemDesignPage> createState() => _SystemDesignPageState();
}
class _SystemDesignPageState extends State<SystemDesignPage> {
List<bool> _isOpen = [false, false, false, false, false, false];
void _handleAdd() {
print("Add FAB pressed");
}
void _handleEdit() {
print("Edit FAB pressed");
}
void _handleDelete() {
print("Delete FAB pressed");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("System design"), centerTitle: true),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ExpansionPanelList(
expansionCallback: (panelIndex, isExpanded) {
setState(() {
_isOpen[panelIndex] = isExpanded;
});
},
children: [
buttonWidget(),
fabWidget(),
outlinedFabWidget(),
paginationWidget(),
tabWidget(),
inputsWidget(),
],
),
),
),
);
}
ExpansionPanel inputsWidget() {
return ExpansionPanel(
isExpanded: _isOpen[5],
headerBuilder: (context, isExpanded) {
return ListTile(
title: Text(
"inputs",
style: AppFonts.yekan20.copyWith(color: Colors.red),
),
);
},
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
spacing: 14,
children: [
RTextField(
hintText: 'حجم کشتار را در روز به قطعه وارد کنید',
hintStyle: AppFonts.yekan13,
),
RTextField(
label: 'تلفن مرغداری',
labelStyle: AppFonts.yekan10,
),
],
),
),
);
}
ExpansionPanel tabWidget() {
return ExpansionPanel(
isExpanded: _isOpen[4],
headerBuilder: (context, isExpanded) {
return ListTile(
title: Text(
"tab",
style: AppFonts.yekan20.copyWith(color: Colors.red),
),
);
},
body: Column(
spacing: 14,
children: [
CupertinoSegmentedControlDemo(),
CupertinoSegmentedControlDemo2(),
],
),
);
}
ExpansionPanel paginationWidget() {
return ExpansionPanel(
isExpanded: _isOpen[3],
headerBuilder: (context, isExpanded) {
return ListTile(
title: Text(
"پیجینیشن",
style: AppFonts.yekan20.copyWith(color: Colors.red),
),
);
},
body: Column(spacing: 14, children: [RShowMore(), PaginationFromUntil()]),
);
}
ExpansionPanel outlinedFabWidget() {
return ExpansionPanel(
isExpanded: _isOpen[2],
headerBuilder: (context, isExpanded) {
return ListTile(
title: Text(
"Outlined Fab ",
style: AppFonts.yekan20.copyWith(color: Colors.green),
),
);
},
body: Column(
spacing: 14,
children: [
Row(),
/*
RFabOutlined.smallAdd(onPressed: () {}),
RFabOutlined.smallAdd(onPressed: null),
RFabOutlined.smallAddNoBorder(onPressed: () {}),
RFabOutlined.smallAddNoBorder(onPressed: null),
RFabOutlined.add(onPressed: () {}),
RFabOutlined.add(onPressed: null),
RFabOutlined.addNoBorder(onPressed: () {}),
RFabOutlined.addNoBorder(onPressed: null),*/
],
),
);
}
ExpansionPanel fabWidget() {
return ExpansionPanel(
isExpanded: _isOpen[1],
headerBuilder: (context, isExpanded) {
return ListTile(
title: Text(
"Fab",
style: AppFonts.yekan20.copyWith(color: Colors.green),
),
);
},
body: Column(
spacing: 14,
children: [
Row(),
/* RFab.smallAdd(onPressed: () {}),
RFab.smallAdd(onPressed: null),
RFab.add(onPressed: () {}),
RFab.add(onPressed: null),
RFab.smallEdit(onPressed: null),
RFab.smallEdit(onPressed: () {}),
RFab.edit(onPressed: () {}),
RFab.edit(onPressed: null),
RFab.smallDelete(onPressed: () {}),
RFab.smallDelete(onPressed: null),
RFab.delete(onPressed: () {}),
RFab.delete(onPressed: null),
RFab.smallAction(onPressed: () {}),
RFab.smallAction(onPressed: null),
RFab.action(onPressed: () {}),
RFab.action(onPressed: null),
RFab.smallFilter(onPressed: () {}),
RFab.smallFilter(onPressed: null),
RFab.filter(onPressed: () {}),
RFab.filter(onPressed: null),
RFab.smallDownload(onPressed: () {}),
RFab.smallDownload(onPressed: null),
RFab.download(onPressed: () {}),
RFab.download(onPressed: null),
RFab.smallExcel(onPressed: () {}),
RFab.smallExcel(onPressed: null),
RFab.excel(onPressed: () {}),
RFab.excel(onPressed: null),
RFab.smallBack(onPressed: () {}),
RFab.smallBack(onPressed: null),
RFab.back(onPressed: () {}),
RFab.back(onPressed: null),*/
],
),
);
}
ExpansionPanel buttonWidget() {
return ExpansionPanel(
isExpanded: _isOpen[0],
headerBuilder: (context, isExpanded) {
return ListTile(
title: Text(
"دکمه ها",
style: AppFonts.yekan20.copyWith(color: Colors.green),
),
);
},
body: Column(
spacing: 14,
children: [
Row(),
RElevated(text: 'ثبت', onPressed: () {}),
RElevated(text: 'ثبت', onPressed: null),
ROutlinedElevated(text: 'ثبت', onPressed: () {}),
ROutlinedElevated(
text: 'ثبتwwww',
onPressed: () {},
backgroundColor: AppColor.blueNormal.disabledColor,
pressedBackgroundColor: AppColor.blueNormal,
),
ROutlinedElevated(text: 'ثبت', onPressed: null),
RTextButton(text: 'ثبت', onPressed: () {}),
RTextButton(text: 'ثبت', onPressed: null),
],
),
);
}
}

View File

@@ -1,15 +1,33 @@
name: auth
description: A starting point for Dart libraries or applications.
publish_to: 'none'
version: 1.0.0
# repository: https://github.com/my_org/my_repo
environment:
sdk: ^3.7.2
# Add regular dependencies here.
dependencies:
# path: ^1.8.0
rasadyar_core:
path: ../core
dev_dependencies:
lints: ^5.0.0
test: ^1.24.0
flutter_test:
sdk: flutter
flutter_lints: ^5.0.0
##code generation
build_runner: ^2.4.15
hive_ce_generator: ^1.9.1
freezed: ^3.0.3
json_serializable: ^6.9.4
##test
mocktail: ^1.0.4
get_test: ^4.0.1
flutter:
uses-material-design: true