Files
Regroup/lib/Main_Screens/ProfileTab/Settings/ChangePassword.dart
2024-07-31 16:08:23 +05:30

183 lines
7.3 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:regroup/Common/CommonButton.dart';
import 'package:regroup/Common/base_manager.dart';
import 'package:regroup/Main_Screens/ProfileTab/view_model/profilePostmethod.dart';
import 'package:regroup/Utils/Common/CommonAppbar.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/resources/routes/route_name.dart';
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
class ChangePassword extends StatefulWidget {
const ChangePassword({super.key});
@override
State<ChangePassword> createState() => _ChangePasswordState();
}
class _ChangePasswordState extends State<ChangePassword> {
TextEditingController currentpasscontroller = TextEditingController();
TextEditingController newpasscontroller = TextEditingController();
TextEditingController repeatpasscontroller = TextEditingController();
Uploadata() async {
utils.loader();
Map<String, dynamic> updata = {
"current_password": currentpasscontroller.text,
"new_password": newpasscontroller.text,
"confirm_password": repeatpasscontroller.text,
};
final data = await Profilepostmethod().postChangepassword(updata);
if (data.status == ResponseStatus.SUCCESS) {
Get.back();
print("Change pass up done");
Get.toNamed(RouteName.verifycode, arguments: {
"currentpass": currentpasscontroller.text,
"newpass": newpasscontroller.text,
"confirmpass": repeatpasscontroller.text
});
return utils.showToast(data.message);
} else {
Get.back();
print("change pass not done");
return utils.showToast(data.message);
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Scaffold(
resizeToAvoidBottomInset: false,
// key: _scaffoldKey1,
backgroundColor: const Color(0xFF222935),
extendBody: true,
appBar: const CommonAppbar(
titleTxt: "Change password",
),
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: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
sizedBoxHeight(25.h),
text16w400_FCFCFC("Current password"),
sizedBoxHeight(16.w),
CustomTextFormField(
textEditingController: currentpasscontroller,
isInputPassword: true,
// textEditingController: _password,
hintText: '',
leadingIcon: Image.asset(
'assets/images/png/lock.png',
width: 22.w,
height: 17.h,
),
// const Icon(Icons.lock_outline),
// validationMessage: "Enter your password",
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter your password';
}
return null;
},
inputFormatters: [
LengthLimitingTextInputFormatter(50),
RemoveEmojiInputFormatter()
],
),
sizedBoxHeight(25.h),
text16w400_FCFCFC("New password"),
sizedBoxHeight(16.w),
CustomTextFormField(
textEditingController: newpasscontroller,
isInputPassword: true,
// textEditingController: _password,
hintText: '',
leadingIcon: Image.asset(
'assets/images/png/lock.png',
width: 22.w,
height: 17.h,
),
// const Icon(Icons.lock_outline),
// validationMessage: "Enter your password",
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter your password';
}
return null;
},
inputFormatters: [
LengthLimitingTextInputFormatter(50),
RemoveEmojiInputFormatter()
],
),
sizedBoxHeight(25.h),
text16w400_FCFCFC("Repeat password"),
sizedBoxHeight(16.w),
CustomTextFormField(
isInputPassword: true,
textEditingController: repeatpasscontroller,
hintText: '',
leadingIcon: Image.asset(
'assets/images/png/lock.png',
width: 22.w,
height: 17.h,
),
// const Icon(Icons.lock_outline),
// validationMessage: "Enter your password",
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter your password';
}
if (val != newpasscontroller.text) {
return 'Password does not match';
}
return null;
},
inputFormatters: [
LengthLimitingTextInputFormatter(50),
RemoveEmojiInputFormatter()
],
),
sizedBoxHeight(50.h),
CommonBtn(
text: "Verify",
onTap: () {
// Get.toNamed(RouteName.verifycode);
if (currentpasscontroller.text.isBlank! &&
newpasscontroller.text.isBlank! &&
repeatpasscontroller.text.isBlank!) {
utils.showToast('Please fill all fields');
} else {
Uploadata();
}
},
)
]),
),
)
])),
);
}
}