Skip to content
Snippets Groups Projects
Commit 94697a53 authored by Rakshitha Salian's avatar Rakshitha Salian
Browse files

Refactoring code

parent 8f6d7208
Branches
No related tags found
1 merge request!2Verify OTP screen- FE -ECAP1-24
......@@ -10,10 +10,10 @@ Future<dynamic> verificationSuccess(
required String title,
required String subtitle}) {
return Get.dialog(
barrierDismissible: false,
barrierColor: AppColor.black.withOpacity(0.5),
Center(
child: SingleChildScrollView(
child: PopScope(canPop: false,
child: AlertDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0))),
......@@ -48,5 +48,6 @@ Future<dynamic> verificationSuccess(
),
),
),
),
));
}
......@@ -115,8 +115,7 @@ class AllHttpRequest {
try {
///Generate authorization token for send otp
String url = '$baseUrlForSendOtp/api/sendsms/token?action=generate';
// String username = 'Exidehtptrans1';
// String password = '_<P)>lnL0{';
String basicAuth =
'Basic ${base64.encode(utf8.encode('${AppConstants.username}:${AppConstants.password}'))}';
Map<String, String>? headers = {
......@@ -134,10 +133,12 @@ class AllHttpRequest {
sendOtp();
} else {
Fluttertoast.showToast(msg: apiError.tr);
log("Error generate auth--${response.statusCode}");
throw Error();
}
} catch (e) {
Fluttertoast.showToast(msg: apiError.tr);
log("Error generate auth--$e");
throw Error();
}
}
......@@ -165,10 +166,12 @@ class AllHttpRequest {
///If success do nothing
} else {
Fluttertoast.showToast(msg: apiError.tr);
log("Error generate auth--${response.statusCode}");
throw Error();
}
} catch (e) {
Fluttertoast.showToast(msg: apiError.tr);
log("Error generate auth--$e");
throw Error();
}
}
......
......@@ -11,9 +11,8 @@ import '../../../customWidget/dialogues/success_dialogue.dart';
class VerifyOtpController extends GetxController {
final baseController = Get.find<BaseController>();
RxInt counter = 20.obs;
RxInt counter = 90.obs;
Timer? timer;
RxString enteredOtp = "".obs;
StreamController<ErrorAnimationType> errorController =
StreamController<ErrorAnimationType>();
TextEditingController otpTextController = TextEditingController();
......@@ -26,10 +25,16 @@ class VerifyOtpController extends GetxController {
super.onInit();
}
@override
void onClose() {
timer?.cancel();
super.onClose();
}
onClickVerifyHandler(BuildContext context) {
verifyLoader(true);
Future.delayed(
const Duration(seconds: 30),
const Duration(seconds: 2),
() => {
if (baseController.generatedOtp.value ==
otpTextController.value.text)
......@@ -42,10 +47,9 @@ class VerifyOtpController extends GetxController {
}
else
{
otpTextController.clear(),
verifyLoader(false),
resetLoading(),
Fluttertoast.showToast(msg: incorrectOTPError.tr)
}
},
});
update();
......@@ -53,11 +57,12 @@ class VerifyOtpController extends GetxController {
onClickResendOTP() {
resetTimer();
startTimer();
otpTextController.clear();
resetLoading();
///During resend otp auth is fetched from state variable and is not regenerated
AllHttpRequest().sendOtp();
update();
AllHttpRequest().generateAuth();
}
startTimer() {
......@@ -76,4 +81,10 @@ class VerifyOtpController extends GetxController {
///Set counter to 90s
counter = 90.obs;
}
resetLoading() {
///Reset Loading and clear otp in pintextfield
otpTextController.clear();
verifyLoader(false);
}
}
import 'package:exide_crr/constants/image_constants.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
import '../../../appLocalization/language_key.dart';
import '../../../constants/app_constants.dart';
import '../../../constants/font_constants.dart';
import '../../../customWidget/app_text.dart';
import '../../../customWidget/button_widget.dart';
import '../../../customWidget/otp_text_field/otp_text_field.dart';
import '../../../customWidget/otp_text_field/otp_text_field_style.dart';
import '../../../res/app_color_text_size.dart';
import '../../../serverRequest/all_request.dart';
import '../../../utils/res/styles.dart';
import '../controller/verify_otp_controller.dart';
import '../../../customWidget/dialogues/success_dialogue.dart';
import '../widgets/floating_button.dart';
import '../widgets/pincode_text_field.dart';
import '../widgets/resend_otp_text.dart';
......
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
import '../../../constants/font_constants.dart';
import '../../../res/app_color_text_size.dart';
import '../../../utils/res/styles.dart';
import '../controller/verify_otp_controller.dart';
......@@ -33,10 +30,6 @@ Widget pinCodeField(VerifyOtpController controller,BuildContext context) {
animationDuration: const Duration(milliseconds: 300),
errorAnimationController: controller.errorController,
controller: controller.otpTextController,
// Pass it here
onChanged: (text) {
controller.enteredOtp(text);
},
appContext: context,
).paddingOnly(top: 8.0.h, bottom: 16.0.h, right: 92.w);
).paddingOnly(top: 8.0.h, bottom: 16, right: 92.w);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment