42 lines
1.3 KiB
Dart
42 lines
1.3 KiB
Dart
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> {
|
|
Rx<TextEditingController> textController = TextEditingController().obs;
|
|
RxnString captchaKey = RxnString();
|
|
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
|
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
|
|
getCaptcha();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
textController.value.dispose();
|
|
super.onClose();
|
|
}
|
|
|
|
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()));
|
|
},
|
|
);
|
|
}
|
|
}
|