mask_text_input_formatter
mask_text_input_formatter copied to clipboard
[Request] Input Mask Right to Left
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
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.
Any updates on this?
Still....
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
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
this tip was very useful, thank you