gtgalone / currency_text_input_formatter

Currency Text Input Formatter for Flutter.
https://pub.dev/packages/currency_text_input_formatter
MIT License
50 stars 28 forks source link

Symbol appears when initialValue is set #32

Closed agharium closed 2 years ago

agharium commented 2 years ago
FormBuilderTextField(
  name: 'value',
  decoration: const InputDecoration(
    labelText: 'Valor'
  ),
  inputFormatters: [
    CurrencyTextInputFormatter(
      locale: 'pt-br',
      decimalDigits: 2,
      symbol: '',
    ),
  ],
  keyboardType: TextInputType.number,
  onChanged: (value) => log(value!.replaceAll('.', '').replaceAll(',', '.')),
  initialValue: action == 'edit' ? _formatter.format(vm.movement.value.toString()) : '',
),

I set symbol as an empty string, and it renders like this:

image

But when initialValue is set, the symbol appears anyway:

image

Can someone help me? 😁🙏

thanks!

gtgalone commented 2 years ago

@agharium Thank you for reporting the issue!

I will figure it out soon.

gtgalone commented 2 years ago

@agharium your code will be changed to

final CurrencyTextInputFormatter _formatter = CurrencyTextInputFormatter(
    locale: 'pt-br',
    decimalDigits: 2,
    symbol: '',
);

TextFormField(
    inputFormatters: [_formatter],
    initialValue: _formatter.format('2000'),
),