53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
|
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class OTPScreenController extends GetxController {
|
|
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
|
// final TextEditingController otpController = TextEditingController(text: "");
|
|
final TextEditingController otpController = TextEditingController(text: "123456");
|
|
RxString otpErrorMsg = "".obs;
|
|
RxBool isLoading = false.obs;
|
|
|
|
bool validateOTP() {
|
|
if(otpController.text.isEmpty) {
|
|
otpErrorMsg.value = ConstantText.kPleaseInputOTP;
|
|
} else if(otpController.text.length<6) {
|
|
otpErrorMsg.value = ConstantText.kInvalidOTP;
|
|
} else {
|
|
otpErrorMsg.value = "";
|
|
}
|
|
return otpErrorMsg.isEmpty;
|
|
}
|
|
|
|
void removeFocus() {
|
|
FocusScope.of(screenKey.currentContext!).unfocus();
|
|
}
|
|
|
|
void onSubmitButton() async {
|
|
if (validateOTP()) {
|
|
var response = await AuthService().verifyOtp(
|
|
verificationCode: otpController.text,
|
|
).showLoader();
|
|
if (response is bool && response == true) {
|
|
Navigator.pushNamedAndRemoveUntil(
|
|
screenKey.currentContext!,
|
|
CustomRouteNames.kDashboardScreenRoute,
|
|
(route) => false,
|
|
);
|
|
} else if (response is String) {
|
|
FrequentFunctions.showToast(message: response);
|
|
} else {
|
|
FrequentFunctions.showToast(message: response.toString());
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
otpController.dispose();
|
|
Get.delete<OTPScreenController>();
|
|
super.dispose();
|
|
}
|
|
} |