From 6e055b568ea8f82bcc63250bac3c850fe07a36d6 Mon Sep 17 00:00:00 2001 From: Fatimah Alshammari Date: Mon, 14 Mar 2022 15:25:15 +0300 Subject: [PATCH] fixed issues --- lib/pages/user/complete_profile_page.dart | 70 ++++++++++++++++++----- lib/pages/user/confirm_new_password.dart | 10 ++++ 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/lib/pages/user/complete_profile_page.dart b/lib/pages/user/complete_profile_page.dart index 162cf22..aa71f19 100644 --- a/lib/pages/user/complete_profile_page.dart +++ b/lib/pages/user/complete_profile_page.dart @@ -26,6 +26,7 @@ class CompleteProfilePage extends StatefulWidget { } class _CompleteProfilePageState extends State { + bool isChecked = false; String? firstName = "", lastName = "", email = "", password = "", confirmPassword = ""; @override @@ -51,6 +52,7 @@ class _CompleteProfilePageState extends State { TxtField( hint: "First Name", + value: firstName, onChanged: (v) { firstName = v; }, @@ -58,6 +60,7 @@ class _CompleteProfilePageState extends State { 12.height, TxtField( hint: "Surname", + value: lastName, onChanged: (v) { lastName = v; }, @@ -65,6 +68,7 @@ class _CompleteProfilePageState extends State { 12.height, TxtField( hint: "Email", + value: email, onChanged: (v) { email = v; }, @@ -74,6 +78,7 @@ class _CompleteProfilePageState extends State { hint: "Create Password", isPasswordEnabled: true, maxLines: 1, + value: password, onChanged: (v) { password = v; }, @@ -83,6 +88,7 @@ class _CompleteProfilePageState extends State { hint: "Confirm Password", isPasswordEnabled: true, maxLines: 1, + value: confirmPassword, onChanged: (v) { confirmPassword = v; }, @@ -92,7 +98,12 @@ class _CompleteProfilePageState extends State { // hint: "Phone Number", // ), 50.height, - "By creating an account you agree to our Terms of Service and Privacy Policy".toText12(), + Row( + children: [ + buildCheckbox(), + "By creating an account you agree to our Terms of Service and\n Privacy Policy".toText12(), + ], + ), 16.height, ShowFillButton( title: "Continue", @@ -107,23 +118,56 @@ class _CompleteProfilePageState extends State { ), ), ); + } + Widget buildCheckbox() => Checkbox( + value: isChecked, + activeColor: Colors.blue, + onChanged: (value){ + setState(() { + isChecked = value!; + }); + }, + ); + Future performCompleteProfile() async { - if (password == confirmPassword) { - print(widget.user.data!.userId??"userId"); - Utils.showLoading(context); - RegisterUser user = await UserApiClent().basicComplete(widget.user.data?.userId ?? "", firstName!, lastName!, email!, password!); - Utils.hideLoading(context); - if (user.messageStatus == 1) { - Utils.showToast( "Successfully Registered, Please login once"); - pop(context); - // navigateReplaceWithName(context, AppRoutes.dashboard,arguments: user); + if (firstName != "") { + if (lastName != "") { + if (validateStructure(password ?? "")) { + if (password == confirmPassword) { + if (isChecked) { + print(widget.user.data!.userId ?? "userId"); + Utils.showLoading(context); + RegisterUser user = await UserApiClent().basicComplete(widget.user.data?.userId ?? "", firstName!, lastName!, email!, password!); + Utils.hideLoading(context); + if (user.messageStatus == 1) { + Utils.showToast("Successfully Registered, Please login once"); + pop(context); + // navigateReplaceWithName(context, AppRoutes.dashboard,arguments: user); + } else { + Utils.showToast(user.message ?? ""); + } + }else{ + Utils.showToast("Please accept terms"); + } + } else { + Utils.showToast("Please enter same password"); + } } else { - Utils.showToast(user.message ?? ""); + Utils.showToast("Password Should contains Character, Number, Capital and small letters"); } - } else { - Utils.showToast("Please enter same password"); + }else{ + Utils.showToast("Surname is mandatory"); + } + }else{ + Utils.showToast("First name is mandatory"); } } + + bool validateStructure(String value){ + String pattern = r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{6,}$'; + RegExp regExp = new RegExp(pattern); + return regExp.hasMatch(value); + } } diff --git a/lib/pages/user/confirm_new_password.dart b/lib/pages/user/confirm_new_password.dart index 2c01938..cc2f39e 100644 --- a/lib/pages/user/confirm_new_password.dart +++ b/lib/pages/user/confirm_new_password.dart @@ -82,6 +82,7 @@ class _ConfirmNewPasswordPageState extends State { } Future confirmPasswordOTP(BuildContext context) async { + if(validateStructure(newPassword??"")){ Utils.showLoading(context); Response res = await UserApiClent().ForgetPassword(widget.userToken, newPassword); Utils.hideLoading(context); @@ -92,6 +93,9 @@ class _ConfirmNewPasswordPageState extends State { } else { Utils.showToast(data.message ?? ""); } + }else{ + Utils.showToast("Password Should contains Character, Number, Capital and small letters"); + } } bool validation() { @@ -102,4 +106,10 @@ class _ConfirmNewPasswordPageState extends State { } return isValid; } + + bool validateStructure(String value){ + String pattern = r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{6,}$'; + RegExp regExp = new RegExp(pattern); + return regExp.hasMatch(value); + } }