Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter (iOS) number keyboard decimal separator

Tags:

ios

flutter

When using numeric keyboard it decides whether to separate the decimals with dot or comma based on the region settings of the phone. For some reason Apple has decided that in the Netherlands it is a comma, yet everybody separates decimals with a dot here.

Changing the region of the phone works, yet not a viable solution.

Is there a way to change ios region globally/fixed?

like image 341
Bro Avatar asked Aug 07 '19 14:08

Bro


1 Answers

Ok, finally found a solution. You can't replace the comma or dot, yet you can use TextFormatter. Example:

class CommaTextInputFormatter extends TextInputFormatter {
 @override
 TextEditingValue formatEditUpdate(
  TextEditingValue oldValue, TextEditingValue newValue) {
  String truncated = newValue.text;
  TextSelection newSelection = newValue.selection;

if (newValue.text.contains(",")) {
  truncated = newValue.text.replaceFirst(RegExp(','), '.');
}
return TextEditingValue(
  text: truncated,
  selection: newSelection,
);

} }

like image 116
Bro Avatar answered Oct 29 '22 10:10

Bro