mask_text_input_formatter icon indicating copy to clipboard operation
mask_text_input_formatter copied to clipboard

Not working mask when add text by TextEditingController

Open II11II opened this issue 4 years ago • 4 comments

Hi there, I cannot format textfield value by adding text by controller

  final TextEditingController _numberKeyboardController =
      TextEditingController();
final phoneTextFormatter = MaskTextInputFormatter(
      mask: "+998 (••) ••• •• ••", filter: {"•": RegExp(r'[0-9]')});
      
      // ui code
         child: PhoneTextFiled(
                maskTextInputFormatter: phoneTextFormatter,
                controller: _numberKeyboardController,
                showCursor: true,
                readOnly: true),
          ),
NumberKeyboard(
               onChanged: (_){
             // from custom NumberKeyboard i pass number to controller
               },
                textEditingController: _numberKeyboardController,
              ),
      // ui code
      

II11II avatar Mar 15 '21 10:03 II11II

anything update yet?

lyseiha avatar Sep 02 '21 04:09 lyseiha

The same issue

arok avatar Nov 15 '21 07:11 arok

+1

fabioginzel avatar Nov 21 '21 19:11 fabioginzel

The formatEditUpdate method is a mirror of Flutter's

image

The method is Called when text is being typed or cut/copy/pasted in the [EditableText].

This means that we can use that to format our text like so:

/// oldValue = _textController.value before assigning a new value to _textController.text and
/// newValue is _textController.value after having assigned it a new text value
_textController.value = _textFormatter.formatEditUpdate(oldValue, newValue);

Khongchai avatar Mar 01 '22 10:03 Khongchai