Flutter(iOS)数字键盘小数点分隔符 [英] Flutter (iOS) number keyboard decimal separator

查看:290
本文介绍了Flutter(iOS)数字键盘小数点分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数字键盘时,它会根据手机的区域设置来决定是用小数点还是逗号分隔小数点.由于某种原因,苹果公司决定在荷兰使用逗号,但每个人都在此处用小数点分隔小数.

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.

是否可以全局/固定更改ios区域?

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

推荐答案

好,终于找到了解决方案.您不能替换逗号或点,但可以使用TextFormatter.示例:

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,
);

} }

这篇关于Flutter(iOS)数字键盘小数点分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆