Closed NTMS2017 closed 4 years ago
I assume this will require a localization formatter inside the Double widget. If anyone know what to do I will add it.
As far as I understand programming you cannot change the format of a number. You must work with a string and then transform it into the 1000000.00 format Computers don't work with symbols inside the number, it's always just "." as a decimal separator and so you must use a mask to display it in the 1.000.000,00 format....
I use the CardSettingsCurrency class
I cloned the CardSettingsCurrency class and created a new class called CardSettingsCurrencyV2 and added the two lines below. I believe it is not an elegant solution, but it worked. I use the thousands separator '.' and decimal separator '.'
with double number, remove the symbol money and unit
`String _safeValidator(String value) {
//Add this line
value = value.replaceAll(widget.thousandSeparator, "").replaceAll(widget.decimalSeparator, ".");
if (widget.validator == null) return null;
return widget.validator(intelligentCast
void _safeOnSaved(String value) {
if (widget.onSaved == null) return;
//Add this line
value = value.replaceAll(widget.thousandSeparator, "").replaceAll(widget.decimalSeparator, ".");
widget.onSaved(intelligentCast
CardSettingsCurrencyV2( showMaterialonIOS: true, key: _valorKey, label: "Valor", currencyName: 'Real', currencySymbol: 'R\$', enabled: true, decimalSeparator: ",", thousandSeparator: ".", autofocus: false, contentAlign: TextAlign.left, initialValue: widget._certificadoAvulso.valor, autovalidate: false, validator: (value) { if (value == null) return 'campo é obrigatório.'; return null; }, onSaved: (value) { print('OnSaved: $value'); widget._certificadoAvulso.valor = value; }, onChanged: (value) { print('Onchange: $value'); setState(() { widget._certificadoAvulso.valor = value; }); }),`
Thank you for posting this workaround. I'm actively trying to solve this internally to CardSettings so this hack isn't needed. By that I mean not by using the cast methods but rather so the value returns a double and not a string with delimiters.
Note, the fix will be implemented as soon as the pattern_formatter package works correctly with international numbers.
I committed a fix for this and Phone as well. Would you be able to test the github build before I publish?
Fixed in version 1.9.8
I need to localize CardSettingsDouble to Turkish due to decimal point. Unfortunately is not working correctly on iOS. Android has no problem. But for iOS keyboard shows only ' , ' sign.
I put this in my code but this is not a correct solution. If I use TextInputType.numberWithOptions(decimal: true) the decimal point shows as a ' , '. Example if I type 12,75 it shows as a 12 only. If I type 12.75 and it shows 12.75 in showResults(). { _buildResultsRow('Toplam Tutar', model.toplamTutar, linebreak: true), }
I need to convert , too . because my server accepts dot as decimal points. Any idea how to correct this?