Files
rasadyar_application/packages/auth/lib/presentation/widget/captcha/logic.dart

42 lines
1.2 KiB
Dart
Raw Normal View History

2025-05-17 09:08:46 +03:30
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_core/core.dart';
class CaptchaWidgetLogic extends GetxController
with StateMixin<CaptchaResponseModel> {
2025-05-17 15:24:06 +03:30
Rx<TextEditingController> textController = TextEditingController().obs;
RxnString captchaKey = RxnString();
2025-05-17 09:08:46 +03:30
GlobalKey<FormState> formKey = GlobalKey<FormState>();
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
@override
void onInit() {
super.onInit();
getCaptcha();
}
@override
void onClose() {
2025-05-17 15:24:06 +03:30
textController.value.dispose();
2025-05-17 09:08:46 +03:30
super.onClose();
}
Future<void> getCaptcha() async {
change(null, status: RxStatus.loading());
2025-05-17 15:24:06 +03:30
textController.value.clear();
2025-05-17 09:08:46 +03:30
safeCall(
call: () async => await authRepository.captcha(),
onSuccess: (value) {
2025-05-17 15:24:06 +03:30
captchaKey.value = value?.captchaKey;
2025-05-17 09:08:46 +03:30
change(value, status: RxStatus.success());
},
onError: (error, stackTrace) {
change(null, status: RxStatus.error(error.toString()));
},
);
}
}