48 lines
1.4 KiB
Dart
48 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:rasadyar_core/core.dart';
|
|
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';
|
|
|
|
class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseModel> {
|
|
TextEditingController textController = TextEditingController();
|
|
RxnString captchaKey = RxnString();
|
|
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
|
AuthRepositoryImpl authRepository = diInspection.get<AuthRepositoryImpl>();
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
|
|
getCaptcha();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
textController.clear();
|
|
textController.dispose();
|
|
super.onClose();
|
|
}
|
|
|
|
Future<void> getCaptcha() async {
|
|
change(null, status: RxStatus.loading());
|
|
textController.clear();
|
|
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) {},
|
|
);
|
|
|
|
change(value, status: RxStatus.success());
|
|
}
|
|
}
|