Files
rasadyar_application/packages/chicken/lib/presentation/widget/captcha/logic.dart
2025-08-02 15:09:06 +03:30

35 lines
864 B
Dart

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
class CaptchaWidgetLogic extends GetxController with StateMixin<String> {
TextEditingController textController = TextEditingController();
RxnString captchaKey = RxnString();
GlobalKey<FormState> formKey = GlobalKey<FormState>();
final Random random = Random();
@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();
await Future.delayed(Duration(milliseconds: 500));
captchaKey.value = (random.nextInt(900_000) + 100_000).toString();
change(captchaKey.value, status: RxStatus.success());
}
}