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

Please add a static method for initialValues #20

Closed khsater closed 3 years ago

khsater commented 3 years ago

It is useful to have a static method for use in pre-filled forms and data tables. Can you please add a static method to format strings for initial values?

gtgalone commented 3 years ago

@khsater Thank you for using.

This is just for formatter.

You can initialize value like below.

https://stackoverflow.com/questions/43214271/how-do-i-supply-an-initial-value-to-a-text-field

khsater commented 3 years ago

@gtgalone , please consider:

double myCurrencyValue;

TextFormField(
   initialValue: myCurrencyValue.toString(),
   onSaved: (value) {
      myCurrencyValue = double.parse(value);
   },
   inputFormatters: [
      CurrencyTextInputFormatter(
           decimalDigits: 2,
           symbol: "\$",
       )],
...
),

In this case, the initial value is not formatted by the formatter. It would be helpful to have access to a static method for this situation when a value must be saved as a double not a formatted string.

gtgalone commented 3 years ago

@khsater That is good idea!

Would you like to make a pull request?

Or I will do it?

FilipKvestak commented 3 years ago

is this implemented now? it would be very helpful to have it initially formatted

gtgalone commented 3 years ago

@FilipKvestak Not yet.

Feel free to contribute.

If nobody do this, I will do it.

gtgalone commented 3 years ago

@khsater @FilipKvestak

Thank you guys!

I have just published for this with 2.1.0

Please use new release :)