From 2b4c019c551a4b40513cdbb2aa677d7b6ad23301 Mon Sep 17 00:00:00 2001 From: MrM Date: Tue, 3 Jun 2025 22:52:21 +0330 Subject: [PATCH] feat : auth for new module --- .../lib/data/common/dio_error_handler.dart | 29 +-- .../auth/lib/data/common/dio_manager.dart | 2 +- packages/auth/lib/data/di/auth_di.dart | 9 +- .../local/user_local/user_local_model.dart | 13 ++ .../local/user_local/user_local_model.g.dart | 10 +- .../response/user_info/user_info_model.dart | 18 ++ .../user_profile_model.dart | 30 +++ .../data/repositories/auth_repository.dart | 10 +- .../repositories/auth_repository_imp.dart | 25 ++- .../data/services/token_storage_service.dart | 16 ++ .../lib/presentation/pages/auth/logic.dart | 73 ++++++- .../lib/presentation/pages/auth/view.dart | 179 +++++++++--------- .../lib/presentation/widget/captcha/view.dart | 15 +- packages/core/lib/core.dart | 10 +- .../lib/infrastructure/remote/dio_remote.dart | 6 +- tools/package_builder.sh | 2 +- 16 files changed, 314 insertions(+), 133 deletions(-) create mode 100644 packages/auth/lib/data/models/response/user_info/user_info_model.dart create mode 100644 packages/auth/lib/data/models/response/user_profile_model/user_profile_model.dart diff --git a/packages/auth/lib/data/common/dio_error_handler.dart b/packages/auth/lib/data/common/dio_error_handler.dart index 963707c..57f29bc 100644 --- a/packages/auth/lib/data/common/dio_error_handler.dart +++ b/packages/auth/lib/data/common/dio_error_handler.dart @@ -5,10 +5,14 @@ class DioErrorHandler { void handle(DioException error) { switch (error.response?.statusCode) { case 401: - _handle401(); + _handleGeneric(error); break; case 403: - _handle403(); + _handleGeneric(error); + break; + + case 410: + _handle410(); break; default: _handleGeneric(error); @@ -16,21 +20,22 @@ class DioErrorHandler { } //wrong password/user name => "detail": "No active account found with the given credentials" - 401 - void _handle401() { - Get.showSnackbar( - _errorSnackBar('نام کاربری یا رمز عبور اشتباه است'), - ); + void _handle410() { + Get.showSnackbar(_errorSnackBar('نام کاربری یا رمز عبور اشتباه است')); } //wrong captcha => "detail": "Captcha code is incorrect" - 403 - void _handle403() { - Get.showSnackbar( - _errorSnackBar('کد امنیتی اشتباه است'), - ); - } + void _handle403() {} void _handleGeneric(DioException error) { - // General error handling + Get.showSnackbar( + _errorSnackBar( + error.response?.data.keys.first == 'is_user' + ? 'کاربر با این شماره تلفن وجود ندارد' + : error.response?.data[error.response?.data.keys.first] ?? + 'خطا در برقراری ارتباط با سرور', + ), + ); } GetSnackBar _errorSnackBar(String message) { diff --git a/packages/auth/lib/data/common/dio_manager.dart b/packages/auth/lib/data/common/dio_manager.dart index 441485a..2c920a0 100644 --- a/packages/auth/lib/data/common/dio_manager.dart +++ b/packages/auth/lib/data/common/dio_manager.dart @@ -12,7 +12,7 @@ class DioRemoteManager { ApiEnvironment env = ApiEnvironment.dam, ]) async { if (_currentEnv != env) { - _currentClient = DioRemote(env.baseUrl); + _currentClient = DioRemote(baseUrl: env.baseUrl); await _currentClient?.init(); _currentEnv = env; } diff --git a/packages/auth/lib/data/di/auth_di.dart b/packages/auth/lib/data/di/auth_di.dart index 190715f..cc89573 100644 --- a/packages/auth/lib/data/di/auth_di.dart +++ b/packages/auth/lib/data/di/auth_di.dart @@ -1,7 +1,6 @@ import 'package:rasadyar_auth/data/common/constant.dart'; import 'package:rasadyar_auth/data/common/dio_error_handler.dart'; import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart'; -import 'package:rasadyar_auth/data/services/token_storage_service.dart'; import 'package:rasadyar_core/core.dart'; import '../common/dio_manager.dart'; @@ -10,12 +9,16 @@ GetIt diAuth = GetIt.instance; Future setupAuthDI() async { diAuth.registerLazySingleton(() => DioRemoteManager()); + diAuth.registerLazySingleton(() => DioRemote()); + /* final manager = diAuth.get(); + final dioRemote = await manager.setEnvironment(ApiEnvironment.dam);*/ - final manager = diAuth.get(); - final dioRemote = await manager.setEnvironment(ApiEnvironment.dam); + final dioRemote = diAuth.get(); + await dioRemote.init(); diAuth.registerCachedFactory( () => AuthRepositoryImpl(dioRemote), ); + diAuth.registerLazySingleton(() => DioErrorHandler()); } diff --git a/packages/auth/lib/data/models/local/user_local/user_local_model.dart b/packages/auth/lib/data/models/local/user_local/user_local_model.dart index 0f603f6..0e18269 100644 --- a/packages/auth/lib/data/models/local/user_local/user_local_model.dart +++ b/packages/auth/lib/data/models/local/user_local/user_local_model.dart @@ -19,6 +19,12 @@ class UserLocalModel extends HiveObject { @HiveField(5) Module? module; + @HiveField(6) + String? backend; + + @HiveField(7) + String? apiKey; + UserLocalModel({ this.username, this.password, @@ -26,6 +32,8 @@ class UserLocalModel extends HiveObject { this.refreshToken, this.name, this.module, + this.backend, + this.apiKey, }); UserLocalModel copyWith({ @@ -35,6 +43,9 @@ class UserLocalModel extends HiveObject { String? refreshToken, String? name, Module? module, + String? backend, + String? apiKey, + }) { return UserLocalModel( username: username ?? this.username, @@ -43,6 +54,8 @@ class UserLocalModel extends HiveObject { refreshToken: refreshToken ?? this.refreshToken, name: name ?? this.name, module: module ?? this.module, + backend: backend ?? this.backend, + apiKey: apiKey ?? this.apiKey, ); } } diff --git a/packages/auth/lib/data/models/local/user_local/user_local_model.g.dart b/packages/auth/lib/data/models/local/user_local/user_local_model.g.dart index 8a40c52..93e49af 100644 --- a/packages/auth/lib/data/models/local/user_local/user_local_model.g.dart +++ b/packages/auth/lib/data/models/local/user_local/user_local_model.g.dart @@ -23,13 +23,15 @@ class UserLocalModelAdapter extends TypeAdapter { refreshToken: fields[3] as String?, name: fields[4] as String?, module: fields[5] as Module?, + backend: fields[6] as String?, + apiKey: fields[7] as String?, ); } @override void write(BinaryWriter writer, UserLocalModel obj) { writer - ..writeByte(6) + ..writeByte(8) ..writeByte(0) ..write(obj.username) ..writeByte(1) @@ -41,7 +43,11 @@ class UserLocalModelAdapter extends TypeAdapter { ..writeByte(4) ..write(obj.name) ..writeByte(5) - ..write(obj.module); + ..write(obj.module) + ..writeByte(6) + ..write(obj.backend) + ..writeByte(7) + ..write(obj.apiKey); } @override diff --git a/packages/auth/lib/data/models/response/user_info/user_info_model.dart b/packages/auth/lib/data/models/response/user_info/user_info_model.dart new file mode 100644 index 0000000..e1a94ea --- /dev/null +++ b/packages/auth/lib/data/models/response/user_info/user_info_model.dart @@ -0,0 +1,18 @@ +import 'package:rasadyar_core/core.dart'; + +part 'user_info_model.freezed.dart'; + +part 'user_info_model.g.dart'; + +@freezed +abstract class UserInfoModel with _$UserInfoModel { + const factory UserInfoModel({ + bool? isUser, + String? address, + String? backend, + String? apiKey, + }) = _UserInfoModel ; + + factory UserInfoModel.fromJson(Map json) => + _$UserInfoModelFromJson(json); +} \ No newline at end of file diff --git a/packages/auth/lib/data/models/response/user_profile_model/user_profile_model.dart b/packages/auth/lib/data/models/response/user_profile_model/user_profile_model.dart new file mode 100644 index 0000000..70a9a40 --- /dev/null +++ b/packages/auth/lib/data/models/response/user_profile_model/user_profile_model.dart @@ -0,0 +1,30 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'user_profile_model.freezed.dart'; + +part 'user_profile_model.g.dart'; + +@freezed +abstract class UserProfileModel with _$UserProfileModel { + const factory UserProfileModel({ + String? accessToken, + String? expiresIn, + String? scope, + String? expireTime, + String? mobile, + String? fullname, + String? firstname, + String? lastname, + String? city, + String? province, + String? nationalCode, + String? nationalId, + String? birthday, + String? image, + int? baseOrder, + List? role, + }) = _UserProfileModel; + + factory UserProfileModel.fromJson(Map json) => + _$UserProfileModelFromJson(json); +} diff --git a/packages/auth/lib/data/repositories/auth_repository.dart b/packages/auth/lib/data/repositories/auth_repository.dart index eb68705..2f5464c 100644 --- a/packages/auth/lib/data/repositories/auth_repository.dart +++ b/packages/auth/lib/data/repositories/auth_repository.dart @@ -1,12 +1,11 @@ - +import 'package:rasadyar_auth/data/models/response/user_info/user_info_model.dart'; import '../models/response/auth/auth_response_model.dart'; import '../models/response/captcha/captcha_response_model.dart'; +import '../models/response/user_profile_model/user_profile_model.dart'; abstract class AuthRepository { - Future login({ - required Map authRequest, - }); + Future login({required Map authRequest}); Future captcha(); @@ -14,10 +13,9 @@ abstract class AuthRepository { Future hasAuthenticated(); - Future loginWithRefreshToken({ required Map authRequest, }); - + Future getUserInfo(String phoneNumber); } diff --git a/packages/auth/lib/data/repositories/auth_repository_imp.dart b/packages/auth/lib/data/repositories/auth_repository_imp.dart index 6f03fc0..c2ef5d1 100644 --- a/packages/auth/lib/data/repositories/auth_repository_imp.dart +++ b/packages/auth/lib/data/repositories/auth_repository_imp.dart @@ -1,3 +1,5 @@ +import 'package:rasadyar_auth/data/models/response/user_info/user_info_model.dart'; +import 'package:rasadyar_auth/data/models/response/user_profile_model/user_profile_model.dart'; import 'package:rasadyar_core/core.dart'; import '../models/response/auth/auth_response_model.dart'; @@ -11,13 +13,13 @@ class AuthRepositoryImpl implements AuthRepository { AuthRepositoryImpl(this._httpClient); @override - Future login({ + Future login({ required Map authRequest, }) async { - var res = await _httpClient.post( - '$_BASE_URL/login/', + var res = await _httpClient.post( + '/api/login/', data: authRequest, - fromJson: AuthResponseModel.fromJson, + fromJson: UserProfileModel.fromJson, headers: {'Content-Type': 'application/json'}, ); return res.data; @@ -59,4 +61,19 @@ class AuthRepositoryImpl implements AuthRepository { return response.data ?? false; } + + @override + Future getUserInfo(String phoneNumber) async { + var res = await _httpClient.post( + 'https://userbackend.rasadyaar.ir/api/send_otp/', + data: { + "mobile": phoneNumber, + "state": "" + }, + fromJson: UserInfoModel.fromJson, + headers: {'Content-Type': 'application/json'}, + ); + return res.data; + + } } diff --git a/packages/auth/lib/data/services/token_storage_service.dart b/packages/auth/lib/data/services/token_storage_service.dart index 0c56166..816a5b6 100644 --- a/packages/auth/lib/data/services/token_storage_service.dart +++ b/packages/auth/lib/data/services/token_storage_service.dart @@ -8,6 +8,8 @@ class TokenStorageService extends GetxService { static const String _boxName = 'secureBox'; static const String _accessTokenKey = 'accessToken'; static const String _refreshTokenKey = 'refreshToken'; + static const String _baseUrlKey = 'baseUrl'; + static const String _apiKey = 'apiKey'; static const String _moduleKey = 'moduleSelected'; final FlutterSecureStorage _secureStorage = FlutterSecureStorage(); @@ -15,6 +17,7 @@ class TokenStorageService extends GetxService { RxnString accessToken = RxnString(); RxnString refreshToken = RxnString(); + RxnString baseurl= RxnString(); Rxn appModule = Rxn(null); Future init() async { @@ -34,6 +37,7 @@ class TokenStorageService extends GetxService { accessToken.value = _localStorage.read(boxName: _boxName, key: _accessTokenKey); refreshToken.value = _localStorage.read(boxName: _boxName, key: _refreshTokenKey); appModule.value = _localStorage.read(boxName: _boxName, key: _moduleKey); + baseurl.value = _localStorage.read(boxName: _boxName, key: _baseUrlKey); } Future saveAccessToken(String token) async { @@ -59,4 +63,16 @@ class TokenStorageService extends GetxService { accessToken.value = null; refreshToken.value = null; } + + + Future saveBaseUrl(String url) async { + await _localStorage.save(boxName: _boxName, key: _baseUrlKey, value: url); + baseurl.value = url; + baseurl.refresh(); + } + + Future saveApiKey(String key) async { + await _localStorage.save(boxName: _boxName, key: _apiKey, value: key); + + } } diff --git a/packages/auth/lib/presentation/pages/auth/logic.dart b/packages/auth/lib/presentation/pages/auth/logic.dart index 37b2e2e..31c6607 100644 --- a/packages/auth/lib/presentation/pages/auth/logic.dart +++ b/packages/auth/lib/presentation/pages/auth/logic.dart @@ -5,6 +5,8 @@ import 'package:rasadyar_auth/auth.dart'; import 'package:rasadyar_auth/data/common/dio_error_handler.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/models/response/user_info/user_info_model.dart'; +import 'package:rasadyar_auth/data/models/response/user_profile_model/user_profile_model.dart'; import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart'; import 'package:rasadyar_auth/data/services/token_storage_service.dart'; import 'package:rasadyar_auth/data/utils/safe_call.dart'; @@ -34,6 +36,7 @@ class AuthLogic extends GetxController { RxnString phoneNumber = RxnString(null); RxBool isLoading = false.obs; + RxBool isDisabled = true.obs; TokenStorageService tokenStorageService = Get.find(); Rx authType = AuthType.useAndPass.obs; @@ -108,7 +111,7 @@ class AuthLogic extends GetxController { ); } - Future submitLoginForm() async { + /*Future submitLoginForm() async { if (!_isFormValid()) return; iLog('module222 : ${_module.toString()}'); final loginRequestModel = _buildLoginRequest(); @@ -128,5 +131,73 @@ class AuthLogic extends GetxController { }, ); isLoading.value = false; + }*/ + + Future submitLoginForm2() async { + if (!_isFormValid()) return; + + isLoading.value = true; + await safeCall( + call: () => authRepository.login( + authRequest: { + "username": phoneNumberController.value.text, + "password": passwordController.value.text, + }, + ), + onSuccess: (result) async { + await tokenStorageService.saveModule(_module); + await tokenStorageService.saveAccessToken(result?.accessToken ?? ''); + await tokenStorageService.saveRefreshToken(result?.accessToken ?? ''); + }, + onError: (error, stackTrace) { + if (error is DioException) { + diAuth.get().handle(error); + } + captchaController.getCaptcha(); + }, + ); + isLoading.value = false; + } + + Future getUserInfo(String value) async { + isLoading.value = true; + await safeCall( + call: () async => await authRepository.getUserInfo(value), + onSuccess: (result) async { + if (result != null) { + diAuth.registerSingleton( + DioRemote(baseUrl: result.backend), + instanceName: 'newDioRemote', + ); + await tokenStorageService.saveApiKey(result.apiKey ?? ''); + await tokenStorageService.saveBaseUrl(result.backend ?? ''); + } + }, + onError: (error, stackTrace) { + if (error is DioException) { + diAuth.get().handle(error); + } + captchaController.getCaptcha(); + }, + ); + isLoading.value = false; + } + + GetSnackBar _errorSnackBar(String message) { + return GetSnackBar( + titleText: Text( + 'خطا', + style: AppFonts.yekan14.copyWith(color: Colors.white), + ), + messageText: Text( + message, + style: AppFonts.yekan12.copyWith(color: Colors.white), + ), + backgroundColor: AppColor.error, + margin: EdgeInsets.symmetric(horizontal: 12, vertical: 8), + borderRadius: 12, + duration: Duration(milliseconds: 3500), + snackPosition: SnackPosition.TOP, + ); } } diff --git a/packages/auth/lib/presentation/pages/auth/view.dart b/packages/auth/lib/presentation/pages/auth/view.dart index 343c050..1002a4f 100644 --- a/packages/auth/lib/presentation/pages/auth/view.dart +++ b/packages/auth/lib/presentation/pages/auth/view.dart @@ -27,7 +27,7 @@ class AuthPage extends GetView { } }, controller.authType), - SizedBox(height: 50), + /* SizedBox(height: 50), RichText( text: TextSpan( children: [ @@ -80,7 +80,7 @@ class AuthPage extends GetView { ], ), ); - }, controller.authType), + }, controller.authType),*/ ], ), ), @@ -94,118 +94,109 @@ class AuthPage extends GetView { key: controller.formKey, child: Column( children: [ - ObxValue( - (phoneController) => - RTextField( - label: 'نام کاربری', - maxLength: 11, - maxLines: 1, - controller: phoneController.value, - keyboardType: TextInputType.text, - initText: phoneController.value.text, - onChanged: (value) { - phoneController.value.text = value; - phoneController.refresh(); - }, - prefixIcon: Padding( - padding: const EdgeInsets.fromLTRB(0, 8, 6, 8), - child: Assets.vec.callSvg.svg( - width: 12, - height: 12, - ), - ), - suffixIcon: - phoneController.value.text - .trim() - .isNotEmpty - ? clearButton(() { - phoneController.value.clear(); - phoneController.refresh(); + RTextField( + label: 'نام کاربری', + maxLength: 11, + maxLines: 1, + controller: controller.phoneNumberController.value, + keyboardType: TextInputType.number, + initText: controller.phoneNumberController.value.text, + onChanged: (value) async { + controller.phoneNumberController.value.text = value; + controller.phoneNumberController.refresh(); + if (value.length == 11) { + await controller.getUserInfo(value); + } + }, + prefixIcon: Padding( + padding: const EdgeInsets.fromLTRB(0, 8, 6, 8), + child: Assets.vec.callSvg.svg(width: 12, height: 12), + ), + suffixIcon: + controller.phoneNumberController.value.text.trim().isNotEmpty + ? clearButton(() { + controller.phoneNumberController.value.clear(); + controller.phoneNumberController.refresh(); }) - : null, - validator: (value) { - if (value == null || value.isEmpty) { - return '⚠️ شماره موبایل را وارد کنید'; - } - /*else if (value.length < 11) { - return '⚠️ شماره موبایل باید 11 رقم باشد'; - }*/ - return null; - }, - style: AppFonts.yekan13, - errorStyle: AppFonts.yekan13.copyWith( - color: AppColor.redNormal, - ), - labelStyle: AppFonts.yekan13, - boxConstraints: const BoxConstraints( - maxHeight: 40, - minHeight: 40, - maxWidth: 40, - minWidth: 40, - ), - ), - controller.phoneNumberController, + : null, + validator: (value) { + if (value == null || value.isEmpty) { + return '⚠️ شماره موبایل را وارد کنید'; + } else if (value.length < 11) { + return '⚠️ شماره موبایل باید 11 رقم باشد'; + } + return null; + }, + style: AppFonts.yekan13, + errorStyle: AppFonts.yekan13.copyWith(color: AppColor.redNormal), + labelStyle: AppFonts.yekan13, + boxConstraints: const BoxConstraints( + maxHeight: 40, + minHeight: 40, + maxWidth: 40, + minWidth: 40, + ), ), const SizedBox(height: 26), ObxValue( - (passwordController) => - RTextField( - label: 'رمز عبور', - filled: false, - controller: passwordController.value, - variant: RTextFieldVariant.password, - initText: passwordController.value.text, - onChanged: (value) { - passwordController.refresh(); - }, - validator: (value) { - if (value == null || value.isEmpty) { - return '⚠️ رمز عبور را وارد کنید'; - } - return null; - }, - style: AppFonts.yekan13, - errorStyle: AppFonts.yekan13.copyWith( - color: AppColor.redNormal, - ), - labelStyle: AppFonts.yekan13, - prefixIcon: Padding( - padding: const EdgeInsets.fromLTRB(0, 8, 8, 8), - child: Assets.vec.keySvg.svg( - width: 12, - height: 12, - ), - ), - boxConstraints: const BoxConstraints( - maxHeight: 34, - minHeight: 34, - maxWidth: 34, - minWidth: 34, - ), - ), + (passwordController) => RTextField( + label: 'رمز عبور', + filled: false, + obscure: true, + controller: passwordController.value, + variant: RTextFieldVariant.password, + initText: passwordController.value.text, + onChanged: (value) { + passwordController.refresh(); + }, + validator: (value) { + if (value == null || value.isEmpty) { + return '⚠️ رمز عبور را وارد کنید'; + } + return null; + }, + style: AppFonts.yekan13, + errorStyle: AppFonts.yekan13.copyWith( + color: AppColor.redNormal, + ), + labelStyle: AppFonts.yekan13, + prefixIcon: Padding( + padding: const EdgeInsets.fromLTRB(0, 8, 8, 8), + child: Assets.vec.keySvg.svg(width: 12, height: 12), + ), + boxConstraints: const BoxConstraints( + maxHeight: 34, + minHeight: 34, + maxWidth: 34, + minWidth: 34, + ), + ), controller.passwordController, ), SizedBox(height: 26), CaptchaWidget(), SizedBox(height: 23), - ObxValue((data) { + + Obx(() { return RElevated( text: 'ورود', - isLoading: data.value, - onPressed: () async { - await controller.submitLoginForm(); - }, + isLoading: controller.isLoading.value, + onPressed: controller.isDisabled.value + ? null + : () async { + await controller.submitLoginForm2(); + }, width: Get.width, height: 48, ); - }, controller.isLoading), + }), ], ), ), ); } -/* + /* Widget sendCodeForm() { return ObxValue((data) { return Form( diff --git a/packages/auth/lib/presentation/widget/captcha/view.dart b/packages/auth/lib/presentation/widget/captcha/view.dart index 125eb9e..b225220 100644 --- a/packages/auth/lib/presentation/widget/captcha/view.dart +++ b/packages/auth/lib/presentation/widget/captcha/view.dart @@ -2,6 +2,7 @@ import 'dart:math'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:rasadyar_auth/presentation/pages/auth/logic.dart'; import 'package:rasadyar_auth/presentation/widget/clear_button.dart'; import 'package:rasadyar_core/core.dart'; @@ -64,9 +65,19 @@ class CaptchaWidget extends GetView { validator: (value) { if (value == null || value.isEmpty) { return 'کد امنیتی را وارد کنید'; + } else if (controller.captchaKey.value != null && controller.captchaKey.value != value) { + return 'کد امنیتی اشتباه است'; } return null; }, + onChanged: (pass) { + if(pass.length== 6) { + if(controller.formKey.currentState?.validate()??false) { + Get.find().isDisabled.value = false; + + } + } + }, style: AppFonts.yekan13, ); }, controller.textController), @@ -82,10 +93,10 @@ class _CaptchaLinePainter extends CustomPainter { void paint(Canvas canvas, Size size) { final random = Random(); final paint1 = Paint() - ..color = Color.fromRGBO(random.nextInt(255), random.nextInt(255), random.nextInt(255), 1) + ..color = Colors.deepOrange ..strokeWidth = 2; final paint2 = Paint() - ..color = Color.fromRGBO(random.nextInt(255), random.nextInt(255), random.nextInt(255), 1) + ..color =Colors.blue ..strokeWidth = 2; // First line: top-left to bottom-right diff --git a/packages/core/lib/core.dart b/packages/core/lib/core.dart index 0197984..bdaabab 100644 --- a/packages/core/lib/core.dart +++ b/packages/core/lib/core.dart @@ -1,6 +1,5 @@ library; - //other packages export 'package:flutter_localizations/flutter_localizations.dart'; export 'package:flutter_map/flutter_map.dart'; @@ -9,13 +8,17 @@ export 'package:flutter_rating_bar/flutter_rating_bar.dart'; export 'package:flutter_slidable/flutter_slidable.dart'; export 'package:font_awesome_flutter/font_awesome_flutter.dart'; export 'package:hive_ce_flutter/hive_flutter.dart'; + //freezed export 'package:freezed_annotation/freezed_annotation.dart'; export 'package:geolocator/geolocator.dart'; -export 'package:get/get.dart'; +export 'package:get/get.dart' hide FormData, MultipartFile, Response; + //di export 'package:get_it/get_it.dart'; export 'injection/di.dart'; +export 'package:dio/dio.dart'; +export 'package:pretty_dio_logger/pretty_dio_logger.dart'; //local storage export 'package:hive_ce_flutter/hive_flutter.dart'; @@ -26,13 +29,12 @@ export 'infrastructure/local/hive_local_storage.dart'; //export 'package:encrypt/encrypt.dart' show Encrypted; //Map and location -export 'package:latlong2/latlong.dart' ; +export 'package:latlong2/latlong.dart'; export 'package:persian_datetime_picker/persian_datetime_picker.dart'; export 'package:rasadyar_core/presentation/common/common.dart'; export 'package:rasadyar_core/presentation/utils/utils.dart'; export 'package:rasadyar_core/presentation/widget/widget.dart'; - //network export 'infrastructure/remote/dio_form_data.dart'; export 'infrastructure/remote/dio_remote.dart'; diff --git a/packages/core/lib/infrastructure/remote/dio_remote.dart b/packages/core/lib/infrastructure/remote/dio_remote.dart index c8f0189..dc92ede 100644 --- a/packages/core/lib/infrastructure/remote/dio_remote.dart +++ b/packages/core/lib/infrastructure/remote/dio_remote.dart @@ -7,14 +7,14 @@ import 'package:rasadyar_core/infrastructure/remote/interfaces/i_form_data.dart' import 'interfaces/i_http_client.dart'; class DioRemote implements IHttpClient { - final String baseUrl; + String? baseUrl; late final Dio _dio; - DioRemote(this.baseUrl); + DioRemote({this.baseUrl}); @override Future init() async { - final dio = Dio(BaseOptions(baseUrl: baseUrl)); + final dio = Dio(BaseOptions(baseUrl: baseUrl??'')); if (kDebugMode) { dio.interceptors.add(PrettyDioLogger( requestHeader: true, diff --git a/tools/package_builder.sh b/tools/package_builder.sh index c14cc59..369f0a5 100644 --- a/tools/package_builder.sh +++ b/tools/package_builder.sh @@ -1,2 +1,2 @@ #!/bin/bash -dart create --template=package ../packages/livestock \ No newline at end of file +dart create --template=package ../packages/chicken \ No newline at end of file