bhrott / flutter-masked-text

A masked text for Flutter.

Home Page:https://pub.dartlang.org/packages/flutter_masked_text

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove mask when deleting

ryankauk opened this issue · comments

Just started using this library and so far so good. The only thing I noticed is when typing the mask gets inserted automatically, I would infer that when deleting it would automatically remove the mask as well. Right now when deleting, you have to manually delete the mask one by one.

Hi @ryankauk could you provide a scenario, a code sample and maybe some prints to let me check the problem?

Hi @benhurott.

Just simply use any masks with non-numeric value.

eg) TextField(controller: MaskedTextController(mask: "(0) 000 000 000"))

When you type digits, there are 2 issues including what @ryankauk said.

  1. With typing the first digit of 0, it displays as '(0', not '(0)'
  2. After typing some more digits, let's say '(0) 12', you have to manually remove brackets with the backspace button which @ryankauk was saying.

Some not very smart but working solution:

my mask
_maskedController = MaskedTextController(mask: '00/00');

and then

_maskedController.beforeChange = (String previous, String next) {
  if (next.length == 3) {
    if (next[2] == '/') {
      _maskedController.text = _maskedController.text.substring(0, _maskedController.text.length - 1);
    }
  }
  return true;
};