intl_phone_number_input
intl_phone_number_input copied to clipboard
Curser issue while formating numbers
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:
- Open dialog
- Type US format number: (e.g. +1 650 555 0001)
- 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
This just happened to our clients yesterday, can any one please address the issue
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
I was told the above code worked on iPhone 11 Pro max..
Encountering the same issue, adding the below line helped me
InternationalPhoneNumberInput(
....
onInputChanged: (PhoneNumber value) {
_phoneNumberController.selection = TextSelection.collapsed(offset: _phoneNumberController.text.length);
}
);
This is new on the new version, it's coming with the update to the PhoneNumberKit on iOS from libphonenumber-iOS
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.
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);
},