Files

48 lines
1.4 KiB
Dart
Raw Permalink Normal View History

2025-05-17 09:08:46 +03:30
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
2025-07-28 15:57:30 +03:30
import 'package:rasadyar_inspection/data/model/response/captcha/captcha_response_model.dart';
import 'package:rasadyar_inspection/data/repositories/auth/auth_repository_imp.dart';
import 'package:rasadyar_inspection/injection/inspection_di.dart';
2025-05-17 09:08:46 +03:30
2025-06-02 09:38:02 +03:30
class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseModel> {
2025-07-06 20:44:11 +03:30
TextEditingController textController = TextEditingController();
2025-05-17 15:24:06 +03:30
RxnString captchaKey = RxnString();
2025-05-17 09:08:46 +03:30
GlobalKey<FormState> formKey = GlobalKey<FormState>();
2025-07-28 15:57:30 +03:30
AuthRepositoryImpl authRepository = diInspection.get<AuthRepositoryImpl>();
2025-05-17 09:08:46 +03:30
@override
void onInit() {
super.onInit();
getCaptcha();
}
@override
void onClose() {
2025-07-07 08:36:26 +03:30
textController.clear();
textController.dispose();
2025-05-17 09:08:46 +03:30
super.onClose();
}
Future<void> getCaptcha() async {
change(null, status: RxStatus.loading());
2025-07-07 08:36:26 +03:30
textController.clear();
2025-07-28 15:57:30 +03:30
formKey.currentState?.reset();
await Future.delayed(Duration(milliseconds: 200));
await safeCall(
call: () async => authRepository.captcha(),
onSuccess: (result) {
if (result == null) {
change(null, status: RxStatus.error('Failed to load captcha'));
return;
}
captchaKey.value = result.captchaKey;
change(result, status: RxStatus.success());
},
onError: (error, stackTrace) {},
);
2025-06-03 16:55:49 +03:30
change(value, status: RxStatus.success());
2025-05-17 09:08:46 +03:30
}
}