Files
Regroup/lib/onboarding/Signup/View/verifyuser.dart
2024-07-29 15:20:19 +05:30

279 lines
10 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
import 'package:regroup/Common/base_manager.dart';
import 'package:regroup/Utils/Common/CommonAppbar.dart';
import 'package:regroup/Utils/Common/CustomNextButton.dart';
import 'package:regroup/Utils/Common/sized_box.dart';
import 'package:regroup/Utils/dialogs.dart';
import 'package:regroup/Utils/texts.dart';
import 'package:regroup/onboarding/Signup/view_model/postmethod.dart';
import 'package:regroup/resources/routes/route_name.dart';
import 'package:timer_button/timer_button.dart';
class VerifyuserScreenState extends StatefulWidget {
const VerifyuserScreenState({super.key});
@override
State<VerifyuserScreenState> createState() => _VerifyuserScreenStateState();
}
class _VerifyuserScreenStateState extends State<VerifyuserScreenState> {
// String accounttype = Get.arguments;
TextEditingController pincode = TextEditingController();
String email = Get.arguments['emailid'];
String userpassword = Get.arguments['password'];
String accounttype = Get.arguments['accounttype'];
int accounttypenumber = Get.arguments["accountypenumber"];
Uploadata() async {
utils.loader();
Map<String, dynamic> updata = {
"email_address": email,
"password": userpassword,
"account_type": accounttypenumber,
"otp": pincode.text
};
// final data = res
final res = await Onboard().Postverifyregisteration(updata);
if (res.status == ResponseStatus.SUCCESS) {
Get.back();
print("verification done");
if (accounttype == 'Individual') {
print('individual selected');
Get.toNamed(
RouteName.tellusindividualscreen,
// arguments: {
// 'pageroute' : "nextscreen"
// }
);
} else if (accounttype == 'Business') {
print('business selected');
Get.toNamed(
RouteName.tellusbusinessscreen,
// arguments: {
// 'pageroute' : "nextscreen"
// }
);
}
return utils.showToast(res.message);
} else {
Get.back();
// btnController.error();
// btnController.reset();
Get.snackbar(
"Error!",
res.data['message'],
duration: const Duration(seconds: 2),
colorText: Colors.white,
backgroundColor: Colors.red,
margin: const EdgeInsets.all(8),
snackStyle: SnackStyle.FLOATING,
snackPosition: SnackPosition.BOTTOM,
);
}
// else {
// Get.back();
// print("verification not done");
// return utils.showToast(data.message);
// }
}
Uploadataresendotp() async {
utils.loader();
Map<String, dynamic> updata = {
"email_address": email,
"password": userpassword,
"account_type": accounttypenumber,
};
final data = await Onboard().Postregisteration(updata);
if (data.status == ResponseStatus.SUCCESS) {
Get.back();
// print("resend up done");
// return utils.showToast(data.message);
Get.snackbar(
"Success!",
'OTP has been sent to your email address!',
duration: const Duration(seconds: 2),
colorText: Colors.white,
backgroundColor: Colors.green,
margin: const EdgeInsets.all(8),
snackStyle: SnackStyle.FLOATING,
snackPosition: SnackPosition.BOTTOM,
);
setState(() {
pincode.clear();
// turnValidation = false;
});
}
// else {
// Get.back();
// print("resend not done");
// return utils.showToast(data.message);
// }
else {
Get.back();
// btnController.error();
// btnController.reset();
Get.snackbar(
"Error!",
data.data['message'],
duration: const Duration(seconds: 2),
colorText: Colors.white,
backgroundColor: Colors.red,
margin: const EdgeInsets.all(8),
snackStyle: SnackStyle.FLOATING,
snackPosition: SnackPosition.BOTTOM,
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color.fromARGB(255, 18, 32, 47),
appBar: const CommonAppbar(
titleTxt: '',
),
body: Stack(
children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/png/Ellipse 1496.png"),
fit: BoxFit.fill)),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
sizedBoxHeight(20.h),
text22400white('Check your email'),
sizedBoxHeight(10.h),
text14400white(
'Enter the verification code that we sent to $email'),
sizedBoxHeight(40.h),
text16400white('Enter code'),
sizedBoxHeight(20.h),
PinCodeTextField(
validator: (value) {
if (value != null && value.isEmpty) {
return "Please Enter verification code";
} else if (value != null && value.length < 4) {
return "OTP length should be at least 4";
}
return null;
},
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp('[0-9]')),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
length: 4,
obscureText: false,
animationType: AnimationType.fade,
pinTheme: PinTheme(
selectedFillColor: const Color(0xFF434A53),
inactiveFillColor: const Color(0xFF434A53),
inactiveColor: const Color(0xFF434A53),
activeColor: const Color(0xFF434A53),
selectedColor: const Color(0xFF434A53),
shape: PinCodeFieldShape.underline,
borderRadius: BorderRadius.circular(5),
fieldHeight: 70,
fieldWidth: 70,
activeFillColor:
// Colors.white
const Color(0xFF303030).withOpacity(0.4),
// textStyle: TextStyle(color: Colors.white, fontSize: 20), // Change text color and font size
),
animationDuration: const Duration(milliseconds: 300),
enableActiveFill: true,
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: pincode,
onCompleted: (v) {
print("Completed");
},
onChanged: (value) {
print(value);
setState(() {
// currentText = value;
});
},
cursorColor: Colors.white,
textStyle: TextStyle(
color: Colors.white,
fontSize: 20.sp,
fontFamily: 'Helvetica',
),
beforeTextPaste: (text) {
print("Allowing to paste $text");
return true;
},
appContext: context,
),
sizedBoxHeight(10.h),
Center(
child: TimerButton(
disabledTextStyle: const TextStyle(color: Colors.red),
activeTextStyle: const TextStyle(color: Colors.white),
disabledColor: const Color(0XFF222935).withOpacity(0.10),
buttonType: ButtonType.textButton,
label: "Resend OTP",
timeOutInSeconds: 120,
//mobile.text.isEmpty ? 1 : 60,
onPressed: () {
setState(() {
Uploadataresendotp();
});
},
// disabledColor: Colors.white,
color: const Color(0XFF222935).withOpacity(0.10),
),
),
const Spacer(
flex: 3,
),
CustomButton(
text: 'Continue',
onPressed: () {
if (pincode.text.isEmpty) {
utils.showToast('Pin field is empty');
} else if (pincode.text.length < 4) {
utils.showToast(
'Pin field must be at least 4 characters long');
} else {
Uploadata();
// if (accounttype == 'Individual') {
// print('individual selected');
// Get.toNamed(RouteName.tellusindividualscreen);
// } else if (accounttype == 'Business') {
// print('business selected');
// Get.toNamed(RouteName.tellusbusinessscreen);
// }
}
}),
const Spacer(
// flex: 2,
),
],
),
)
],
),
);
}
}