siqwin / mask_text_input_formatter

Masked text input formatter for flutter.
MIT License
254 stars 54 forks source link

There is a problem entering mask text: masktext #89

Closed MrErkinjon closed 9 months ago

MrErkinjon commented 9 months ago

https://github.com/siqwin/mask_text_input_formatter/assets/97740214/56230359-b1e8-4b8b-a55a-92e1b7a45d47

MrErkinjon commented 9 months ago

after entering the phone number through the code, all the numbers are deleted when editing.

mateus1441 commented 9 months ago

after entering the phone number through the code, all the numbers are deleted when editing.

Same situation with me.

TextFormField( keyboardType: TextInputType.number, inputFormatters: [ MaskTextInputFormatter( mask: '#####-###', filter: {"#": RegExp(r'[0-9]')} ) ], )

siqwin commented 9 months ago

Flutter does not format the value on attach controller to text field, so this must be done manually, something like that:

@override
void initState() {
  super.initState();
  textEditingController.value = maskTextInputFormatter.formatEditUpdate(TextEditingValue.empty, const TextEditingValue(text: "Some initial value"));
}