161 lines
6.1 KiB
Dart
161 lines
6.1 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get.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/CustomTextformfield.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/forgotPass/ViewModel/ForgotPassAPI.dart';
|
||
import 'package:regroup/resources/routes/route_name.dart';
|
||
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
||
class ForgotPass extends StatefulWidget {
|
||
const ForgotPass({super.key});
|
||
|
||
@override
|
||
State<ForgotPass> createState() => _ForgotPassState();
|
||
}
|
||
|
||
class _ForgotPassState extends State<ForgotPass> {
|
||
TextEditingController emailController = TextEditingController();
|
||
// final _formKey = GlobalKey<FormState>();
|
||
|
||
checkValidation() async {
|
||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||
|
||
if (emailController.text.isEmpty) {
|
||
utils.showToast('Enter a email address');
|
||
} else if (!emailController.text.isEmail) {
|
||
utils.showToast('Enter a valid email address');
|
||
} else {
|
||
// Get.toNamed(RouteName.verifyusercreen,
|
||
// arguments: {
|
||
// "emailAddress": emailController.text
|
||
// });
|
||
|
||
Map<String, String> updata = {
|
||
"email_address": emailController.text,
|
||
};
|
||
final resp = await ForgotPassAPI().requestotp(updata);
|
||
if (resp.status == ResponseStatus.SUCCESS) {
|
||
Get.snackbar(
|
||
"Success!",
|
||
'OTP sent successfully!',
|
||
duration: const Duration(seconds: 2),
|
||
colorText: Colors.white,
|
||
backgroundColor: Colors.green,
|
||
margin: const EdgeInsets.all(8),
|
||
snackStyle: SnackStyle.FLOATING,
|
||
snackPosition: SnackPosition.BOTTOM,
|
||
);
|
||
prefs.setString('email', emailController.text);
|
||
prefs.setInt('principal_xid', resp.data['data']['iam_principal_xid']);
|
||
Future.delayed(const Duration(seconds: 1), () {
|
||
Get.toNamed(RouteName.forgotOtp, arguments: emailController.text);
|
||
});
|
||
// print('success');
|
||
} else if (resp.status == ResponseStatus.FAILED) {
|
||
Get.snackbar(
|
||
"Error!",
|
||
resp.message,
|
||
duration: const Duration(seconds: 2),
|
||
colorText: Colors.white,
|
||
backgroundColor: Colors.red,
|
||
margin: const EdgeInsets.all(8),
|
||
snackStyle: SnackStyle.FLOATING,
|
||
snackPosition: SnackPosition.BOTTOM,
|
||
);
|
||
} else {
|
||
// btnController.error();
|
||
// btnController.reset();
|
||
Get.snackbar(
|
||
"Error!",
|
||
resp.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(
|
||
// key: _scaffoldKey1,
|
||
backgroundColor: const Color(0xFF222935),
|
||
extendBody: true,
|
||
resizeToAvoidBottomInset: false,
|
||
appBar: const CommonAppbar(
|
||
titleTxt: "",
|
||
),
|
||
body: Stack(children: [
|
||
Container(
|
||
decoration: const BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage("assets/images/png/Ellipse 1496.png"),
|
||
fit: BoxFit.fill)),
|
||
),
|
||
SingleChildScrollView(
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
sizedBoxHeight(30.h),
|
||
text22400white("Forgot password"),
|
||
sizedBoxHeight(15.h),
|
||
Container(
|
||
height: 1.h,
|
||
width: 250.w,
|
||
color: const Color(0xFF858585),
|
||
),
|
||
sizedBoxHeight(35.h),
|
||
text16w400_FCFCFC("Email address"),
|
||
sizedBoxHeight(15.h),
|
||
CustomTextFormField(
|
||
textEditingController: emailController,
|
||
leadingIcon: SizedBox(
|
||
height: 18.h,
|
||
width: 23.w,
|
||
child: Center(
|
||
child: Image.asset(
|
||
"assets/images/png/Frame 12 (1).png",
|
||
height: 18.h,
|
||
width: 23.w,
|
||
),
|
||
),
|
||
),
|
||
// hintText: "loremipsum@gmail.comess",
|
||
validator: (value) {
|
||
if (value!.isEmpty) {
|
||
return 'Enter your e-mail address';
|
||
}
|
||
if (!RegExp(
|
||
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$')
|
||
.hasMatch(value)) {
|
||
return 'Enter a valid e-mail address';
|
||
}
|
||
return null;
|
||
},
|
||
),
|
||
sizedBoxHeight(8.h),
|
||
text12w400_8E8E8E(
|
||
"We’ll send four digit code to the registered email"),
|
||
sizedBoxHeight(90.h),
|
||
CustomButton(
|
||
text: 'Continue',
|
||
onPressed: () {
|
||
checkValidation();
|
||
}),
|
||
])))
|
||
]));
|
||
}
|
||
}
|