intl_phone_number_input icon indicating copy to clipboard operation
intl_phone_number_input copied to clipboard

Curser issue while formating numbers

Open Navil opened this issue 2 years ago • 7 comments

Describe the bug On iOS, when typing a US formated number (there are probably more cases), the cursor jumps to the wrong position after formating.

Package version 0.7.2

Flutter version 3.3.10

To Reproduce Only reproducable on iOS Steps to reproduce the behavior:

  1. Open dialog
  2. Type US format number: (e.g. +1 650 555 0001)
  3. The cursor will jump to the wrong position after adding the ( )

Expected behavior The cursor should not jump.

Screenshots

https://user-images.githubusercontent.com/3436399/212307759-4f8f0142-b612-46e3-ba40-6cee0062ccfe.mp4

** Targeted platforms (please complete the following information):**

  • OS: iOS only

Navil avatar Jan 13 '23 11:01 Navil

This just happened to our clients yesterday, can any one please address the issue

tewedaj avatar Jan 14 '23 07:01 tewedaj

TextEditingController controller = TextEditingController(); InternationalPhoneNumberInput( inputBorder: InputBorder.none, maxLength: Platform.isAndroid? 12 : 20, onInputChanged: (PhoneNumber number) { userDetail.phoneNumber = number.phoneNumber.toString(); controller.selection = TextSelection.collapsed(offset: controller.text.length); }, textFieldController: controller, formatInput: true, )

can you try doing something like this? i don't have IOS on me right now.. try it and let me know if it worked for you

tewedaj avatar Jan 14 '23 07:01 tewedaj

I was told the above code worked on iPhone 11 Pro max..

tewedaj avatar Jan 14 '23 15:01 tewedaj

Encountering the same issue, adding the below line helped me

InternationalPhoneNumberInput(
  ....
  onInputChanged: (PhoneNumber value) {
     _phoneNumberController.selection = TextSelection.collapsed(offset: _phoneNumberController.text.length);
  }
);

mingzew avatar Jan 26 '23 08:01 mingzew

This is new on the new version, it's coming with the update to the PhoneNumberKit on iOS from libphonenumber-iOS

iabdousd avatar Feb 04 '23 12:02 iabdousd

The issue is originating from utils/formatter/as_you_type_formatter.dart Line 86: TextEditingValue( text: parsedText, selection: TextSelection.collapsed(offset: parsedText.length), )

It is possible to solve it by replacing selection to this: selection: TextSelection.collapsed(offset: parsedText.length)

If this doesn't break somewhere else, please somebody commit this to codebase, thanks.

MahdiFakhrabadi avatar Feb 08 '23 11:02 MahdiFakhrabadi

In onInputChanged method, add the following line

numCont.selection = TextSelection.collapsed(offset: numCont.text.length);

and numCont is your own TextEditingController.

Here is the full code:

onInputChanged: (PhoneNumber number) {
        numCont.selection = TextSelection.collapsed(offset: numCont.text.length);
        },

Shehzad1Dev avatar May 03 '23 06:05 Shehzad1Dev