feat : captcha widget

This commit is contained in:
2025-06-03 16:55:49 +03:30
parent 288915b354
commit ae18a5f648
9 changed files with 76 additions and 99 deletions

View File

@@ -1,8 +1,9 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:rasadyar_auth/data/di/auth_di.dart';
import 'package:rasadyar_auth/data/models/response/captcha/captcha_response_model.dart';
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
import 'package:rasadyar_auth/data/utils/safe_call.dart';
import 'package:rasadyar_core/core.dart';
class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseModel> {
@@ -10,6 +11,7 @@ class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseM
RxnString captchaKey = RxnString();
GlobalKey<FormState> formKey = GlobalKey<FormState>();
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
final Random random = Random();
@override
void onInit() {
@@ -27,15 +29,9 @@ class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseM
Future<void> getCaptcha() async {
change(null, status: RxStatus.loading());
textController.value.clear();
safeCall(
call: () async => await authRepository.captcha(),
onSuccess: (value) {
captchaKey.value = value?.captchaKey;
change(value, status: RxStatus.success());
},
onError: (error, stackTrace) {
change(null, status: RxStatus.error(error.toString()));
},
);
await Future.delayed(Duration(milliseconds: 800));
captchaKey.value = (random.nextInt(999999)+1000).toString();
change(value, status: RxStatus.success());
}
}