Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Editing a character in the middle of the text (possible solution). #41

Open
FabioBachi opened this issue Sep 18, 2019 · 1 comment

Comments

@FabioBachi
Copy link

FabioBachi commented Sep 18, 2019

I was going through a problem when editing a value in a masked input. For example, if the user typed his phone "(54) 99999-9999" and wanted to change it to "(54) 94999-9999" the input would put the number 4 in the end of the text, like "(54) 99999-9994".

So, following the initial suggestion made by Marc in the #16 , i change the text method to this:

@override
set text(String newText) {
  print(newText);
  if (super.text != newText) {
    int position = this.selection.baseOffset >= super.text.length
        ? (newText ?? '').length
        : this.selection.baseOffset;
    value = value.copyWith(
        text: newText,
        selection: TextSelection.collapsed(offset: position),
        composing: TextRange.empty);
  }
}

Basically, I only put the cursor at the end of the text, if it was already at the end.

Hope it helps (:

@ParsaGachkar
Copy link

thanks but this is not working correctly either. Imagine value 15,000,000.
changing it into 12,000,000 or 10,000,000 works perfectly fine. but when you try to change it into 15,500,000 you endup with value 15,000,005 :D anyway thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants