0

When i set keyboardType: TextInputType.numberWithOptions(decimal: true), my flutter app shows a comma in real device instead to show the point as in the simulator. The aim is to show the point so the app can run some calculation, that otherwise it would not do with a comma.

See pic below

enter image description here

Giovanni
  • 512
  • 2
  • 6
  • 23

1 Answers1

2

Probably you added locale in your project. Open the xcworkspace file on Xcode, select project runner and in info select locales under localisations. Check here if any other locale is added other en_US

Or when using the value from TextEditingController you can replace all comma with a period.

Like

double newVal = double.tryParse(_textController.text.replaceAll(",","."))??0.0;
Kaushik Chandru
  • 15,510
  • 2
  • 12
  • 30
  • yes there is a local in my project. I added 2 more languages plus the English. So, you telling that it shows comma or point based on the locale? How to solve this? – Giovanni Jul 29 '22 at 10:53
  • You can either remove locale or add keyboard with option without decimal true and add input formatter to allow only digits and . – Kaushik Chandru Jul 29 '22 at 10:56
  • Thanks! I wrote the syntax without ```??0.0``` and it worked out. What is the difference? – Giovanni Jul 29 '22 at 15:07
  • If you do try parse there is a chance it may return null so if you add ?? 0.0 it will assign 0.0 if null – Kaushik Chandru Jul 29 '22 at 15:33
  • ok got it. But i get this message: 33:22: Warning: Operand of null-aware operation '??' has type 'double' which excludes null. acDes = double.parse(_textEditingController.text.replaceAll(",", "."))??0.0; – Giovanni Jul 30 '22 at 07:20
  • Here you used double.parse which will definitely return a null.. double.tryParse will return nullable double – Kaushik Chandru Jul 30 '22 at 07:24
  • so what is your suggestion? change double to float or no to put ```??0.0``` – Giovanni Jul 30 '22 at 07:27
  • No i am saying double.parse(textcontroller.text) is expected to give a double value for sure. And double.tryParse(textConteoller.text) is expected to give a double that can also be null. So for example if the user typed nothing and you tried parsing double it will throw error so if you give double.parse() it will first try then if it fails it will se to 0.0 – Kaushik Chandru Jul 30 '22 at 07:37
  • There are 2 methods.. parse and tryParse – Kaushik Chandru Jul 30 '22 at 07:37
  • This cannot be the right answer - "remove locale" to have the dot :) I have a similar problem - iPhone running locale with ',' and flutter app with locale on but currently with English locale set and then the virtual keyboard in the app shows the ',' instead of '.' – Picard Jul 12 '23 at 06:42