gtgalone / currency_text_input_formatter

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

Format default value in TextFormField #19

Closed chitgoks closed 3 years ago

chitgoks commented 3 years ago

hi. how can it be formatted by default? this is my code

TextFormField(
                        decoration: InputDecoration(labelText: tr('premium')),
                        enabled: connectivityResult != ConnectivityResult.none,
                        initialValue: _policy?.premium == 0 ? '' : _policy?.premium.toString(),
                        inputFormatters: [ CurrencyTextInputFormatter(symbol: '') ],
                        keyboardType: TextInputType.numberWithOptions(decimal: true),
                        textInputAction: TextInputAction.next,
                        validator: (String? value) {
                          return value!.isEmpty ? tr('premium_blank') : null;
                        },
                        onChanged: (value) {
                          if (value.replaceAll(',', '').length > 0)
                            _policy?.premium = double.parse(value.replaceAll(',', ''));
                        },
                      ),

The lib works ok when typing. but when it's loaded, it doesnt do any formatting.

luis-cruzt commented 2 years ago

Hi, how did you managed this?

chitgoks commented 2 years ago

Hi, how did you managed this?

sorry, what? what do you mean how i managed this?