feat : captcha widget.dart
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_auth/auth.dart';
|
||||
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
enum AuthType { useAndPass, otp }
|
||||
@@ -18,8 +20,7 @@ class AuthLogic extends GetxController {
|
||||
Rx<TextEditingController> phoneOtpNumberController =
|
||||
TextEditingController().obs;
|
||||
Rx<TextEditingController> otpCodeController = TextEditingController().obs;
|
||||
CaptchaController captchaController = CaptchaController();
|
||||
CaptchaController captchaOtpController = CaptchaController();
|
||||
|
||||
|
||||
RxnString phoneNumber = RxnString(null);
|
||||
RxnString password = RxnString(null);
|
||||
@@ -32,6 +33,8 @@ class AuthLogic extends GetxController {
|
||||
RxInt secondsRemaining = 120.obs;
|
||||
Timer? _timer;
|
||||
|
||||
AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
|
||||
|
||||
void startTimer() {
|
||||
_timer?.cancel();
|
||||
secondsRemaining.value = 120;
|
||||
@@ -55,6 +58,12 @@ class AuthLogic extends GetxController {
|
||||
return '${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
@@ -66,4 +75,6 @@ class AuthLogic extends GetxController {
|
||||
_timer?.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_auth/presentation/widget/captcha/view.dart';
|
||||
import 'package:rasadyar_auth/presentation/widget/clear_button.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
|
||||
|
||||
class AuthPage extends GetView<AuthLogic> {
|
||||
const AuthPage({super.key});
|
||||
|
||||
@@ -21,7 +21,7 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
ObxValue((types) {
|
||||
switch (types.value) {
|
||||
case AuthType.otp:
|
||||
return otpForm();
|
||||
//return otpForm();
|
||||
case AuthType.useAndPass:
|
||||
return useAndPassFrom();
|
||||
}
|
||||
@@ -222,7 +222,7 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
}, controller.passwordController),
|
||||
SizedBox(height: 26),
|
||||
|
||||
CaptchaWidget(controller: controller.captchaController),
|
||||
CaptchaWidget(),
|
||||
|
||||
SizedBox(height: 23),
|
||||
RElevated(
|
||||
@@ -237,9 +237,6 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
initialEntryMode: PersianDatePickerEntryMode.calendarOnly,
|
||||
initialDatePickerMode: PersianDatePickerMode.year,
|
||||
);
|
||||
|
||||
if (data.value.currentState?.validate() == true &&
|
||||
controller.captchaController.validate()) {}
|
||||
},
|
||||
width: Get.width,
|
||||
height: 48,
|
||||
@@ -251,7 +248,7 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
}, controller.formKey);
|
||||
}
|
||||
|
||||
Widget otpForm() {
|
||||
/* Widget otpForm() {
|
||||
return ObxValue((status) {
|
||||
switch (status.value) {
|
||||
case OtpStatus.init:
|
||||
@@ -262,7 +259,7 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
return confirmCodeForm();
|
||||
}
|
||||
}, controller.otpStatus);
|
||||
}
|
||||
}*/
|
||||
|
||||
Widget sendCodeForm() {
|
||||
return ObxValue((data) {
|
||||
@@ -335,14 +332,13 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
|
||||
SizedBox(height: 26),
|
||||
|
||||
CaptchaWidget(controller: controller.captchaOtpController),
|
||||
CaptchaWidget(),
|
||||
|
||||
SizedBox(height: 23),
|
||||
RElevated(
|
||||
text: 'ارسال رمز یکبار مصرف',
|
||||
onPressed: () {
|
||||
if (data.value.currentState?.validate() == true &&
|
||||
controller.captchaOtpController.validate()) {
|
||||
if (data.value.currentState?.validate() == true) {
|
||||
controller.otpStatus.value = OtpStatus.sent;
|
||||
controller.startTimer();
|
||||
}
|
||||
@@ -473,7 +469,6 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
controller.otpStatus.value = OtpStatus.init;
|
||||
controller.captchaOtpController.clear();
|
||||
},
|
||||
text: ' ویرایش',
|
||||
style: AppFonts.yekan14.copyWith(
|
||||
@@ -489,8 +484,7 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
text: 'ورود',
|
||||
onPressed: () {
|
||||
if (controller.formKeyOtp.value.currentState?.validate() ==
|
||||
true &&
|
||||
controller.captchaOtpController.validate()) {}
|
||||
true) {}
|
||||
},
|
||||
width: Get.width,
|
||||
height: 48,
|
||||
@@ -514,11 +508,4 @@ class AuthPage extends GetView<AuthLogic> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget clearButton(VoidCallback onTap) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Icon(CupertinoIcons.multiply_circle, size: 24),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
8
packages/auth/lib/presentation/widget/clear_button.dart
Normal file
8
packages/auth/lib/presentation/widget/clear_button.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
Widget clearButton(VoidCallback onTap) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Icon(CupertinoIcons.multiply_circle, size: 24),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user