221 lines
8.2 KiB
Dart
221 lines
8.2 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:pin_code_fields/pin_code_fields.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:traderscircuit/Utils/Common/CommonAppbar.dart';
|
|
import 'package:traderscircuit/Utils/Common/commonBotton.dart';
|
|
import 'package:traderscircuit/Utils/base_manager.dart';
|
|
import 'package:traderscircuit/Utils/text.dart';
|
|
import 'package:traderscircuit/Utils/utils.dart';
|
|
import 'package:traderscircuit/resources/routes/route_name.dart';
|
|
import 'package:traderscircuit/view/onBoarding/splashScreen1.dart';
|
|
import 'package:traderscircuit/view_model/Login/verify_number_api.dart';
|
|
|
|
bool? isVendorExist;
|
|
int? isProfileUpdated;
|
|
int? isriskProfileUpdated;
|
|
int? isKycUpdated;
|
|
int? isSecuredAccess;
|
|
|
|
class VerifyOTP extends StatefulWidget {
|
|
const VerifyOTP({super.key});
|
|
|
|
@override
|
|
State<VerifyOTP> createState() => _VerifyOTPState();
|
|
}
|
|
|
|
class _VerifyOTPState extends State<VerifyOTP> {
|
|
final GlobalKey<FormState> _otpform = GlobalKey<FormState>();
|
|
TextEditingController pincode = TextEditingController();
|
|
Color primaryColor = Colors.transparent.withOpacity(0.2);
|
|
Color secondaryColor = Colors.grey.shade800;
|
|
String? phonenumber;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
phonenumber = Get.arguments["phonenumber"];
|
|
}
|
|
|
|
_verifycheck() async {
|
|
final isValid = _otpform.currentState?.validate();
|
|
if (isValid!) {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
Utils.loader();
|
|
// print("PLAYER ID ==> ${prefs.getString("playerId")}");
|
|
Map<String, String> updata = {
|
|
"mobile_number": phonenumber.toString(),
|
|
"otp": pincode.text,
|
|
"playerId": prefs.getString("playerId")!,
|
|
};
|
|
final resp = await VerifyNumberAPI(updata).verifynumberApi();
|
|
if (resp.status == ResponseStatus.SUCCESS) {
|
|
log(resp.data.toString());
|
|
Get.back();
|
|
isVendorExist = resp.data["data"]["vendor_account_exist"];
|
|
isProfileUpdated = resp.data["data"]["user_data"]["profile_updated"];
|
|
isriskProfileUpdated =
|
|
resp.data["data"]["user_data"]["risk_profile_updated"];
|
|
isKycUpdated = resp.data["data"]["user_data"]["kyc_updated"];
|
|
isSecuredAccess = resp.data["data"]["user_data"]["secured_access"];
|
|
|
|
if (isVendorExist!) {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString(
|
|
'accessToken', resp.data["data"]["access-token"]);
|
|
// await prefs.setString('productType',
|
|
// resp.data["data"]["nature_of_business_id"].toString());
|
|
// naturebusiness =
|
|
// resp.data["data"]["nature_of_business_id"].toString();
|
|
|
|
// ProfileApi().GetProfileApi().then(
|
|
// (value) {
|
|
|
|
// isSecuredAccess == 0
|
|
// ? Get.toNamed(RouteName.secureaccess)
|
|
// :
|
|
isProfileUpdated == 0
|
|
? Get.toNamed(RouteName.adddetails)
|
|
: isKycUpdated == 0
|
|
? Get.toNamed(RouteName.kyc)
|
|
: isriskProfileUpdated == 0
|
|
? Get.toNamed(RouteName.updateriskprofile)
|
|
: Get.toNamed(RouteName.mainscreen);
|
|
|
|
// Get.toNamed(RouteName.mainscreen);
|
|
// },
|
|
// );
|
|
|
|
// Get.to(() => CustomBottomBar(pageIndex: 0));
|
|
} else {
|
|
Get.toNamed(RouteName.loginscreen);
|
|
}
|
|
} else if (resp.status == ResponseStatus.PRIVATE) {
|
|
Get.back();
|
|
String? message = resp.data['message'];
|
|
Utils.showToast("$message");
|
|
} else if (resp.status == ResponseStatus.ERROR) {
|
|
Get.back();
|
|
String? message = resp.data['message'];
|
|
Utils.showToast("$message");
|
|
} else {
|
|
Get.back();
|
|
String? message = resp.message;
|
|
Utils.showToast(message);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: const CommonAppbar(titleTxt: "Verify OTP"),
|
|
backgroundColor: Colors.black,
|
|
extendBody: true,
|
|
body: Stack(
|
|
children: [
|
|
const CommonBlurLeft(),
|
|
const CommonBlurRight(),
|
|
Stack(
|
|
children: [
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
|
child: Form(
|
|
key: _otpform,
|
|
child: ListView(
|
|
physics: const BouncingScrollPhysics(),
|
|
// mainAxisAlignment: MainAxisAlignment.start,
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
text18W400("Enter four digit code send to"),
|
|
SizedBox(
|
|
height: 100.h,
|
|
),
|
|
Container(
|
|
child: PinCodeTextField(
|
|
showCursor: true,
|
|
cursorColor: Colors.white,
|
|
hintStyle:
|
|
TextStyle(fontSize: 18.sp, color: Colors.white),
|
|
textStyle:
|
|
TextStyle(fontSize: 18.sp, color: Colors.white),
|
|
errorTextSpace: 22,
|
|
validator: (value) {
|
|
if (value != null && value.isEmpty) {
|
|
return "Please Enter verification code";
|
|
} else if (value != null && value.length < 4) {
|
|
return "OTP length should be atleast 4";
|
|
}
|
|
return null;
|
|
},
|
|
keyboardType: TextInputType.number,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
length: 4,
|
|
obscureText: false,
|
|
animationType: AnimationType.fade,
|
|
pinTheme: PinTheme(
|
|
selectedFillColor: primaryColor,
|
|
inactiveFillColor: primaryColor,
|
|
activeFillColor: primaryColor,
|
|
inactiveColor: secondaryColor,
|
|
activeColor: secondaryColor,
|
|
selectedColor: secondaryColor,
|
|
shape: PinCodeFieldShape.box,
|
|
borderRadius: BorderRadius.circular(15),
|
|
fieldHeight: 60.h,
|
|
fieldWidth: 60.w,
|
|
),
|
|
animationDuration: const Duration(milliseconds: 300),
|
|
enableActiveFill: true,
|
|
controller: pincode,
|
|
onCompleted: (v) {
|
|
print("Completed");
|
|
},
|
|
onChanged: (value) {
|
|
print(value);
|
|
setState(() {});
|
|
},
|
|
beforeTextPaste: (text) {
|
|
print("Allowing to paste $text");
|
|
|
|
return true;
|
|
},
|
|
appContext: context,
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 45.h,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
text16W700("Resend Code"),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 200.h,
|
|
),
|
|
CommonBtn(
|
|
text: "Verify OTP",
|
|
onTap: () {
|
|
_verifycheck();
|
|
// Get.toNamed(RouteName.secureaccess);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|