35 lines
864 B
Dart
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());
|
|
}
|
|
}
|