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

标签 ios flutter

使用数字键盘时,它会根据手机的区域设置决定是用点还是逗号分隔小数。出于某种原因,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/

相关文章:

objective-c - 将 NSString 中的文本转换为 8 字节 ASCII Hex 等效值,然后存储回 NSString

ios - 在 iOS7 64 位中添加

ios - 你能拥有多个 UnityAppController 的子类吗?

google-maps - NoSuchMethodError : The method 'toJson' was called on null. - 在 Flutter 中使用 Google map 和 Firestore

flutter : how to left aligned a checkbox

ios - 如何使用 Autoresizing Masks 对 UIImageView 进行舍入?

iphone - IOS rss 订阅登录

android-studio - Flutter doctor 错误 - 找不到 Android sdkmanager 工具。 window

firebase - whenComplete() 方法未按预期工作 - Flutter Async

flutter - 是否可以使用返回 Future 的函数过滤列表?