feat : captcha widget
This commit is contained in:
@@ -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());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user