Flutter (iOS) 数字键盘小数点分隔符

Bro*_*Bro 6 ios flutter

使用数字键盘时,它会根据手机的区域设置决定是用点还是逗号分隔小数。出于某种原因,Apple 决定在荷兰使用逗号,但这里每个人都用点分隔小数。

更改电话区域有效,但不是可行的解决方案。

有没有办法全局/固定更改ios区域?

Bro*_*Bro 9

好的,终于找到了解决办法。您不能替换逗号或点,但可以使用 TextFormatter。例子:

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,
);
Run Code Online (Sandbox Code Playgroud)

} }