使用数字键盘时,它会根据手机的区域设置决定是用点还是逗号分隔小数。出于某种原因,Apple 决定在荷兰使用逗号,但这里每个人都用点分隔小数。
更改电话区域有效,但不是可行的解决方案。
有没有办法全局/固定更改ios区域?
最佳答案
好的,终于找到了解决办法。您不能替换逗号或点,但可以使用 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,
);
}
}
关于ios - Flutter (iOS) 数字键盘小数点分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57397259/