mask_text_input_formatter icon indicating copy to clipboard operation
mask_text_input_formatter copied to clipboard

[Request] Input Mask Right to Left

Open benitogonzalezh opened this issue 4 years ago • 7 comments

Add an option to apply the mask from right to left in the input.

Example with RL option activated:

Mask ##.###.###-#

Expected Behaviur 17.173.127-2 2.412.412-5

Normal Behaviur (how it works now) 17.173.127-2 24.124.125

benitogonzalezh avatar Sep 21 '20 18:09 benitogonzalezh

I also need this for currency masking.

For example, if I have a currency mask and I input "1", I expect the mask to be applied as $ 00.1 instead of $ 1, starting from the cents, right to left.

mateusfccp avatar Oct 15 '20 10:10 mateusfccp

Any updates on this?

Still....

daybson avatar Nov 18 '20 17:11 daybson

You can use this code

inputFormatters: <TextInputFormatter>[
                            // _moneyMaskFormatter
                            TextInputFormatter.withFunction(
                                (oldValue, newValue) {
                              String newText = newValue.text
                                  // .replaceAll(MoneyTextFormField._cents, '')
                                  .replaceAll('.', '')
                                  .replaceAll(',', '')
                                  .replaceAll('_', '')
                                  .replaceAll('-', '');

                              String value = newText;
                              int cursorPosition = newText.length;

                              if (newText.isNotEmpty) {
                                value = _formatCurrency(
                                  double.parse(newText),
                                );
                                cursorPosition = value.length;
                              }

                              return TextEditingValue(
                                text: value,
                                selection: TextSelection.collapsed(
                                  offset: cursorPosition,
                                ),
                              );
                            }),
                          ],
String _formatCurrency(num value) {
    ArgumentError.checkNotNull(value, 'value');

    value = value / 100;

    return NumberFormat.currency(
      // customPattern: '###.###,##',
      customPattern: '###,###.##',
      // locale: 'pt_BR',
    ).format(value);
  }

I need this feature as well

yuriescl avatar Mar 30 '21 11:03 yuriescl

I couldn't quite understand what you want so I can't implement :/ - if someone can explain it better, I can worry about implementing what I'm currently working on the financial mask

giovannism20 avatar Jul 22 '21 18:07 giovannism20

this tip was very useful, thank you

jheimes-silveira avatar Jul 27 '21 21:07 jheimes-silveira