From e6898267300948ebfbf6ccfe4c9b1e41036031a6 Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Wed, 13 Aug 2025 17:15:35 +0300 Subject: [PATCH] login fixes --- lib/config/localized_values.dart | 4 +- .../otp/otp_validation_bootmsheet_widget.dart | 15 +++++-- lib/pages/landing/landing_page.dart | 4 ++ lib/pages/login/register_new.dart | 42 ++++++++++--------- lib/pages/login/register_new_step_2.dart | 14 +++++-- lib/pages/login/saved_login.dart | 7 +++- lib/pages/login/welcome.dart | 10 ++++- lib/uitl/translations_delegate_base.dart | 4 ++ lib/uitl/utils.dart | 26 +++++++++++- 9 files changed, 91 insertions(+), 35 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index eb14cadc..4bdf0696 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -2365,7 +2365,9 @@ const Map localizedValues = { "notice": {"en": "Notice", "ar":"إشعار"}, "receiveOtpToast": {"en": "Where would you like to receive OTP?", "ar":"أين تود تلقي رمز التحقق OTP؟"}, "pleaseChooseOption": {"en": "Please select from the below options to receive OTP.", "ar":"الرجاء اختيار من الخيارات أدناه لتلقي رمز التحقق OTP."}, - + "pleaseEnterMobile": {"en": "Please enter phone number", "ar":"الرجاء إدخال رقم الهاتف"}, + "pleaseEnterValidMobile": {"en": "Please enter valid phone number", "ar":"الرجاء إدخال رقم هاتف صالح"}, + "pleaseEnterNationalIdOrFileNo": {"en": "Please enter National id or File no", "ar":"الرجاء إدخال رقم الهوية الوطنية أو رقم الملف"}, diff --git a/lib/new_ui/otp/otp_validation_bootmsheet_widget.dart b/lib/new_ui/otp/otp_validation_bootmsheet_widget.dart index 11ab1260..9fc6d8ae 100644 --- a/lib/new_ui/otp/otp_validation_bootmsheet_widget.dart +++ b/lib/new_ui/otp/otp_validation_bootmsheet_widget.dart @@ -20,7 +20,7 @@ class GenericBottomSheet extends StatefulWidget { final bool isEnableCountryDropdown; final bool isFromSavedLogin; Function(String?)? onChange; - + FocusNode myFocusNode; GenericBottomSheet( {this.countryCode = "", this.initialPhoneNumber = "", @@ -30,7 +30,9 @@ class GenericBottomSheet extends StatefulWidget { this.onCountryChange, this.isEnableCountryDropdown = false, this.isFromSavedLogin = false, - this.onChange}); + this.onChange, + required this.myFocusNode + }); @override _GenericBottomSheetState createState() => _GenericBottomSheetState(); @@ -138,7 +140,7 @@ class _GenericBottomSheetState extends State { } }, isEnable: true, - autoFocus: true, + focusNode: widget.myFocusNode, isReadOnly: widget.isFromSavedLogin, prefix: widget.isForEmail ? null : widget.countryCode, hasSelection: false, @@ -182,7 +184,7 @@ class CustomButton extends StatelessWidget { final String? fontFamily; final FontWeight fontWeight; final bool isDisabled; - + final Color iconColor; CustomButton({ Key? key, required this.text, @@ -198,6 +200,7 @@ class CustomButton extends StatelessWidget { this.fontWeight = FontWeight.w500, this.isDisabled = false, this.icon, + this.iconColor = Colors.white, }) : super(key: key); @override @@ -222,6 +225,10 @@ class CustomButton extends StatelessWidget { padding: const EdgeInsets.only(right: 8.0), child: SvgPicture.asset( icon!, + colorFilter: ColorFilter.mode( + isDisabled ? iconColor.withOpacity(0.5) : iconColor, + BlendMode.srcIn, + ), width: 24, height: 24, ), diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index df11a666..b413f7a2 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -808,6 +808,10 @@ class _LandingPageState extends State with WidgetsBindingObserver { await sharedPref.setInt(LAST_LOGIN, lastLogin); showQuickLoginBottomSheet(context, user, deviceToken, true); + + Future.delayed(Duration(seconds: 3), () { + Navigator.of(context).pop(); + }); insertIMEI(lastLogin, deviceToken); } } diff --git a/lib/pages/login/register_new.dart b/lib/pages/login/register_new.dart index d6aea8c5..34b753d8 100644 --- a/lib/pages/login/register_new.dart +++ b/lib/pages/login/register_new.dart @@ -66,7 +66,7 @@ class _RegisterNew extends State { final nationalIDorFile = TextEditingController(); final phoneController = TextEditingController(); AppointmentRateViewModel appointmentRateViewModel = locator(); - + final FocusNode myFocusNode = FocusNode(); Country selectedCountry = Country.saudiArabia; OTPType? otpType; bool isTermsAccepted = false; @@ -324,7 +324,8 @@ class _RegisterNew extends State { // Utils.showErrorToast(TranslationBase.of(context).pleaseEnterNationalId); return; } - if (nationalIDorFile != null && !Utils.validateIqama(nationalIDorFile.text)) { + if ((!Utils.validateIqama(nationalIDorFile.text) && selectedCountry.countryCode == '966') || + (!Utils.validateUaeNationalId(nationalIDorFile.text) && selectedCountry.countryCode == '971')) { context.showBottomSheet( child: ExceptionBottomSheet( message: "Please enter correct national id", @@ -401,7 +402,18 @@ class _RegisterNew extends State { if (mobileNo.isEmpty) { context.showBottomSheet( child: ExceptionBottomSheet( - message: "Please enter mobile number", + message: TranslationBase.of(context).pleaseEnterMobile, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); + } + else if (!Utils.validateMobileNumber(mobileNo)) { + context.showBottomSheet( + child: ExceptionBottomSheet( + message: TranslationBase.of(context).pleaseEnterValidMobile, showCancel: false, onOkPressed: () { Navigator.of(context).pop(); @@ -409,19 +421,6 @@ class _RegisterNew extends State { ), ); } - // - // else if (mobileNo.length < 8) { - // context.showBottomSheet( - // child: ExceptionBottomSheet( - // message: "Please enter correct mobile number", - // showCancel: false, - // onOkPressed: () { - // Navigator.of(context).pop(); - // }, - // ), - // ); - // } - else { registerUser(1); } @@ -456,17 +455,17 @@ class _RegisterNew extends State { if (mobileNo.isEmpty) { context.showBottomSheet( child: ExceptionBottomSheet( - message: "Please enter mobile number", + message: TranslationBase.of(context).pleaseEnterMobile, showCancel: false, onOkPressed: () { Navigator.of(context).pop(); }, ), ); - } else if (mobileNo.length < 9) { + } else if (!Utils.validateMobileNumber(mobileNo)) { context.showBottomSheet( child: ExceptionBottomSheet( - message: "Please enter correct mobile number", + message: TranslationBase.of(context).pleaseEnterValidMobile, showCancel: false, onOkPressed: () { Navigator.of(context).pop(); @@ -485,11 +484,14 @@ class _RegisterNew extends State { icon: "assets/images/svg/whatsapp.svg", ), ), - ], + ], myFocusNode:myFocusNode, ), ), ), ); + Future.delayed(Duration(milliseconds: 500), () { + myFocusNode.requestFocus(); + }); }, fontFamily: context.fontFamily, ), diff --git a/lib/pages/login/register_new_step_2.dart b/lib/pages/login/register_new_step_2.dart index 7efbbef1..b5323803 100644 --- a/lib/pages/login/register_new_step_2.dart +++ b/lib/pages/login/register_new_step_2.dart @@ -57,7 +57,7 @@ class _RegisterNew extends State { late ProjectViewModel projectViewModel; bool isFromDubai = false; List countriesList = []; - + final FocusNode myFocusNode = FocusNode(); // TextEditingController nationality = TextEditingController(); String? name, nationalId; @@ -336,6 +336,7 @@ class _RegisterNew extends State { backgroundColor: Color(0xFFFEE9EA), borderColor: Color(0xFFFEE9EA), textColor: Color(0xFFED1C2B), + iconColor: Color(0xFFED1C2B), ), ), SizedBox( @@ -343,10 +344,12 @@ class _RegisterNew extends State { ), Expanded( child: CustomButton( - backgroundColor: Color(0xFF18C273), - borderColor: Color(0xFF18C273), + backgroundColor: Color(0xFFccedde), + borderColor: Color(0xFFccedde), + textColor: Color(0xFF18C273), text: TranslationBase.of(context).confirm, icon: "assets/images/svg/confirm.svg", + iconColor: Color(0xFF18C273), onPressed: () { if (isFromDubai) { if (name == null) { @@ -396,11 +399,14 @@ class _RegisterNew extends State { borderColor: Color(0xFF18C273), textColor: Colors.white), ), - ], + ], myFocusNode: myFocusNode, ), ), ), ); + Future.delayed(Duration(milliseconds: 500), () { + myFocusNode.requestFocus(); + }); }, fontFamily: context.fontFamily, ), diff --git a/lib/pages/login/saved_login.dart b/lib/pages/login/saved_login.dart index f59d5571..3ba48cf5 100644 --- a/lib/pages/login/saved_login.dart +++ b/lib/pages/login/saved_login.dart @@ -54,7 +54,7 @@ class _SavedLogin extends State { TextEditingController? phoneController; final authService = AuthProvider(); late ProjectViewModel projectViewModel; - + final FocusNode myFocusNode = FocusNode(); late ToDoCountProviderModel toDoProvider; Country selectedCountry = Country.saudiArabia; @@ -295,12 +295,15 @@ class _SavedLogin extends State { icon: "assets/images/svg/whatsapp.svg", ), ), - ], + ], myFocusNode: myFocusNode, ), ), ); }), ); + Future.delayed(Duration(milliseconds: 500), () { + myFocusNode.requestFocus(); + }); }, backgroundColor: Colors.white, borderColor: Color(0xFF2E3039), diff --git a/lib/pages/login/welcome.dart b/lib/pages/login/welcome.dart index 54bed02e..ff35c8a6 100644 --- a/lib/pages/login/welcome.dart +++ b/lib/pages/login/welcome.dart @@ -77,6 +77,7 @@ class _WelcomeLogin extends State { AuthenticatedUserObject authenticatedUserObject = locator(); AppointmentRateViewModel appointmentRateViewModel = locator(); late ProjectViewModel projectViewModel; + final FocusNode myFocusNode = FocusNode(); late ToDoCountProviderModel toDoProvider; @@ -189,6 +190,7 @@ class _WelcomeLogin extends State { text: TranslationBase.of(context).login, icon: "assets/images/svg/login1.svg", onPressed: () { + if (nationIdController.text.isNotEmpty) { showModalBottomSheet( context: context, @@ -199,6 +201,7 @@ class _WelcomeLogin extends State { enableDrag: false, // Prevent dragging to avoid focus conflicts builder: (bottomSheetContext) => StatefulBuilder(builder: (BuildContext context, StateSetter setModalState) { + return Padding( padding: EdgeInsets.only(bottom: MediaQuery.of(bottomSheetContext).viewInsets.bottom), child: SingleChildScrollView( @@ -258,16 +261,19 @@ class _WelcomeLogin extends State { icon: "assets/images/svg/whatsapp.svg", ), ), - ], + ], myFocusNode: myFocusNode, ), ), ); }), ); + Future.delayed(Duration(milliseconds: 500), () { + myFocusNode.requestFocus(); + }); } else { context.showBottomSheet( child: ExceptionBottomSheet( - message: "Please enter National id or File no", + message: TranslationBase.of(context).pleaseEnterNationalIdOrFileNo, showCancel: false, onOkPressed: () { Navigator.of(context).pop(); diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index a1b0aaf7..0d36fc8b 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -3512,6 +3512,10 @@ class TranslationBase { String get notice => localizedValues["notice"][locale.languageCode]; String get receiveOtpToast => localizedValues["receiveOtpToast"][locale.languageCode]; String get pleaseChooseOption => localizedValues["pleaseChooseOption"][locale.languageCode]; + String get pleaseEnterMobile => localizedValues["pleaseEnterMobile"][locale.languageCode]; + String get pleaseEnterValidMobile => localizedValues["pleaseEnterValidMobile"][locale.languageCode]; + String get pleaseEnterNationalIdOrFileNo => localizedValues["pleaseEnterNationalIdOrFileNo"][locale.languageCode]; + String get readMore => localizedValues["readMore"][locale.languageCode]; String get showLess => localizedValues["showLess"][locale.languageCode]; diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index a4486e83..7f76c4cd 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -82,15 +82,26 @@ enum MaritalStatusType { single, married, divorced, widowed } class Utils { static int? onOtpBtnPressed(OTPType type, String? phoneNumber, BuildContext context) { - if (phoneNumber == null || phoneNumber.isEmpty || phoneNumber.length < 9) { + if (phoneNumber == null || phoneNumber.isEmpty) { context.showBottomSheet( child: ExceptionBottomSheet( - message: "Please enter your phone number.", + message: TranslationBase.of(context).pleaseEnterMobile, onOkPressed: () { Navigator.of(context).pop(); }, )); return null; + } else if (!Utils.validateMobileNumber(phoneNumber)) { + context.showBottomSheet( + child: ExceptionBottomSheet( + message: TranslationBase.of(context).pleaseEnterValidMobile, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); + return null; } return type == OTPType.sms ? 1 : 4; } @@ -114,6 +125,17 @@ class Utils { return sum % 10 == 0; } + static bool validateUaeNationalId(String id) { + // Must be exactly 15 digits + final regex = RegExp(r'^784\d{4}\d{7}\d{1}$'); + return regex.hasMatch(id); + } + + static bool validateMobileNumber(String number) { + final regex = RegExp(r'^(05\d{8}|5\d{8})$'); + return regex.hasMatch(number); + } + static void changeAppLanguage({required BuildContext context}) { sharedPref.setBool(IS_ROBOT_INIT, false); sharedPref.remove(CLINICS_LIST);