From ff12e832ab7f6de7bc7ffafa2e1f05b06e32036a Mon Sep 17 00:00:00 2001 From: Aamir Muhammad Date: Mon, 11 Aug 2025 10:12:25 +0300 Subject: [PATCH] fixes --- .../otp/otp_validation_bootmsheet_widget.dart | 17 ++++--- .../health_calculator/carbs/carbs.dart | 1 + lib/pages/login/register_new.dart | 1 + lib/pages/login/welcome.dart | 44 ++++++++++++------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/lib/new_ui/otp/otp_validation_bootmsheet_widget.dart b/lib/new_ui/otp/otp_validation_bootmsheet_widget.dart index 89d1d930..5cd2bc4a 100644 --- a/lib/new_ui/otp/otp_validation_bootmsheet_widget.dart +++ b/lib/new_ui/otp/otp_validation_bootmsheet_widget.dart @@ -19,6 +19,7 @@ class GenericBottomSheet extends StatefulWidget { final bool isEnableCountryDropdown; final bool isFromSavedLogin; Function(String?)? onChange; + FocusNode? focusNode; GenericBottomSheet( {Key? key, @@ -30,6 +31,7 @@ class GenericBottomSheet extends StatefulWidget { this.onCountryChange, this.isEnableCountryDropdown = false, this.isFromSavedLogin = false, + this.focusNode, this.onChange}) : super(key: key); @@ -38,18 +40,18 @@ class GenericBottomSheet extends StatefulWidget { } class _GenericBottomSheetState extends State { - // FocusNode node = FocusNode(); - @override void initState() { super.initState(); + if (!widget.isForEmail) { widget.textController = TextEditingController(text: widget.initialPhoneNumber); } + } - // WidgetsBinding.instance.addPostFrameCallback((_) { - // FocusScope.of(context).requestFocus(node); - // }); + @override + void dispose() { + super.dispose(); } @override @@ -59,7 +61,8 @@ class _GenericBottomSheetState extends State { bottom: Platform.isIOS ? false : true, child: GestureDetector( onTap: () { - FocusScope.of(context).unfocus(); // Dismiss the keyboard when tapping outside + // Only unfocus if the tap is not on the text field area + FocusScope.of(context).unfocus(); }, child: Builder(builder: (context) { // final isRtl = Directionality.of(context) == TextDirection.rtl; @@ -104,6 +107,7 @@ class _GenericBottomSheetState extends State { widget.isForEmail ? TranslationBase.of(context).email : TranslationBase.of(context).phoneNumber, widget.isForEmail ? "demo@gmail.com" : "5xxxxxxxx", widget.textController!, + focusNode: widget.focusNode!, padding: EdgeInsets.only(top: 8, bottom: 8, left: 8, right: 8), keyboardType: widget.isForEmail ? TextInputType.emailAddress : TextInputType.number, onChange: (value) { @@ -113,7 +117,6 @@ class _GenericBottomSheetState extends State { } }, isEnable: true, - // focusNode: node, autoFocus: true, isReadOnly: widget.isFromSavedLogin, prefix: widget.isForEmail ? null : widget.countryCode, diff --git a/lib/pages/AlHabibMedicalService/health_calculator/carbs/carbs.dart b/lib/pages/AlHabibMedicalService/health_calculator/carbs/carbs.dart index 112b079e..18f17591 100644 --- a/lib/pages/AlHabibMedicalService/health_calculator/carbs/carbs.dart +++ b/lib/pages/AlHabibMedicalService/health_calculator/carbs/carbs.dart @@ -766,6 +766,7 @@ Widget newInputWidget( readOnly: isReadOnly, textAlignVertical: TextAlignVertical.top, textAlign: TextAlign.left, + textDirection: TextDirection.ltr, onChanged: onChange, focusNode: focusNode, diff --git a/lib/pages/login/register_new.dart b/lib/pages/login/register_new.dart index 093a954b..2fcb9e63 100644 --- a/lib/pages/login/register_new.dart +++ b/lib/pages/login/register_new.dart @@ -222,6 +222,7 @@ class _RegisterNew extends State { hasSelection: false, isBorderAllowed: false, isAllowLeadingIcon: true, + autoFocus: true, padding: const EdgeInsets.only(top: 8, bottom: 8, left: 0, right: 0), leadingIcon: "assets/images/svg/student-card.svg", onChange: (value) { print(value); diff --git a/lib/pages/login/welcome.dart b/lib/pages/login/welcome.dart index 3bd8a0de..4c863962 100644 --- a/lib/pages/login/welcome.dart +++ b/lib/pages/login/welcome.dart @@ -90,13 +90,22 @@ class _WelcomeLogin extends State { late int isHijri; var healthId; + late FocusNode _focusNode; + @override void initState() { isLoading = true; super.initState(); + _focusNode = FocusNode(); phoneController = TextEditingController(); } + @override + void dispose() { + _focusNode.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { projectViewModel = context.read(); @@ -172,6 +181,7 @@ class _WelcomeLogin extends State { removePadding: true, prefix: null, hasSelection: false, + autoFocus: true, isBorderAllowed: false, isAllowLeadingIcon: true, padding: EdgeInsets.only(top: 8, bottom: 8, left: 8, right: 8), @@ -190,6 +200,8 @@ class _WelcomeLogin extends State { isDismissible: false, useSafeArea: true, backgroundColor: Colors.transparent, + 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), @@ -198,6 +210,7 @@ class _WelcomeLogin extends State { countryCode: selectedCountry.countryCode, initialPhoneNumber: phoneNumber != null ? phoneNumber : "", textController: phoneController, + focusNode: _focusNode, isEnableCountryDropdown: true, onCountryChange: (value) { selectedCountry = value; @@ -205,6 +218,15 @@ class _WelcomeLogin extends State { }, onChange: (String? value) { phoneNumber = value; + // WidgetsBinding.instance.addPostFrameCallback((_) { + // Future.delayed(Duration(milliseconds: 300), () { + // if (mounted && _focusNode.canRequestFocus) { + // _focusNode.requestFocus(); + // } + // }); + // }); + + FocusNode().requestFocus(_focusNode); }, buttons: [ Padding( @@ -342,13 +364,13 @@ class _WelcomeLogin extends State { GifLoaderDialogUtils.hideDialog(context); context.showBottomSheet( child: ExceptionBottomSheet( - message: err.toString(), - showCancel: true, - onOkPressed: () { - Navigator.of(context).pop(); - Navigator.of(context).push(FadePage(page: RegisterNew())); - }, - )); + message: err.toString(), + showCancel: true, + onOkPressed: () { + Navigator.of(context).pop(); + Navigator.of(context).push(FadePage(page: RegisterNew())); + }, + )); projectViewModel.analytics.loginRegistration.login_fail(error: err.toString()); }); } @@ -438,14 +460,6 @@ class _WelcomeLogin extends State { if (activation.errorCode == '699') { GifLoaderDialogUtils.hideDialog(context); onWrongActivationCode(activation.errorEndUserMessage); - // context.showBottomSheet( - // child: ExceptionBottomSheet( - // message: activation.errorEndUserMessage, - // onOkPressed: () { - // Navigator.of(context).pop(); - // }, - // ), - // ); return; } else if (registerd_data?.isRegister == true) { Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew));