feat : captcha widget.dart

This commit is contained in:
2025-05-14 15:01:03 +03:30
parent a132b21b18
commit 3a017b5956
10 changed files with 57 additions and 305 deletions

View File

@@ -1,5 +1,5 @@
enum ApiEnvironment {
dam(url: 'https://api.dam.rasadyar.net');
dam(url: 'https://api.dam.rasadyar.net/');
const ApiEnvironment({required this.url});

View File

@@ -8,9 +8,12 @@ class DioRemoteManager {
DioRemote? _currentClient;
ApiEnvironment? _currentEnv;
DioRemote setEnvironment(ApiEnvironment env) {
Future<DioRemote> setEnvironment([
ApiEnvironment env = ApiEnvironment.dam,
]) async {
if (_currentEnv != env) {
_currentClient = DioRemote(env.baseUrl);
await _currentClient?.init();
_currentEnv = env;
}
return _currentClient!;
@@ -30,10 +33,10 @@ class DioRemoteManager {
Future<void> switchAuthEnvironment(ApiEnvironment env) async {
final manager = diAuth.get<DioRemoteManager>();
final dioRemote = manager.setEnvironment(env);
final dioRemote = await manager.setEnvironment(env);
if (diAuth.isRegistered<AuthRepositoryImpl>()) {
await diAuth.unregister<AuthRepositoryImpl>();
await diAuth.unregister<AuthRepositoryImpl>();
}
diAuth.registerLazySingleton<AuthRepositoryImpl>(

View File

@@ -12,14 +12,10 @@ Future<void> setupAuthDI() async {
diAuth.registerLazySingleton(() => DioRemoteManager());
final manager = diAuth.get<DioRemoteManager>();
final dioRemote = manager.setEnvironment(ApiEnvironment.dam);
diAuth.registerLazySingleton<AuthRepositoryImpl>(
final dioRemote = await manager.setEnvironment(ApiEnvironment.dam);
diAuth.registerCachedFactory<AuthRepositoryImpl>(
() => AuthRepositoryImpl(dioRemote),
);
diAuth.registerLazySingleton(() => AuthService());
diAuth.registerLazySingleton(() => TokenStorageService());
//hive
//await diAuth.registerCachedFactoryAsync(() async=>await ,)
}

View File

@@ -34,17 +34,18 @@ class AuthRepositoryImpl implements AuthRepository {
@override
Future<CaptchaResponseModel?> captcha() async {
final response = await safeCall<DioResponse<CaptchaResponseModel>>(
final response = await safeCall(
call:
() async => await _httpClient.post<CaptchaResponseModel>(
'$_BASE_URL/login/',
'captcha/',
headers: {'Content-Type': 'application/json'},
fromJson: CaptchaResponseModel.fromJson
),
onSuccess: (response) {
iLog(response);
},
onError: (error, trace) {
throw Exception('Error during sign in: $error');
throw Exception('Error during captcha : $error');
},
);