wordpress播客主題濰坊seo招聘
? ? ? ? 由于業(yè)務需求,要限制TextField只能輸入中文,但是測試在iOS測試機發(fā)現自帶中文輸入法會變英文輸入問題,安卓沒有問題,并且只有iOS自帶輸入法有問題,搜狗等輸入法沒問題。我們目前使用flutter2.5.3版本,高版本應該不存在這個問題。
????????TextField限制中文代碼片段:
TextField(inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[a-zA-Z]|[\u4e00-\u9fa5]|[0-9]')),],
)
? ? ? ? 解決方案,自定義過濾器:
//自定義過濾器
class CustomizedTextInputFormatter extends TextInputFormatter {final Pattern filterPattern;CustomizedTextInputFormatter({this.filterPattern}): assert(filterPattern != null);@overrideTextEditingValue formatEditUpdate(TextEditingValue oldValue,TextEditingValue newValue,) {if (newValue.isComposingRangeValid) return newValue;return FilteringTextInputFormatter.allow(filterPattern).formatEditUpdate(oldValue, newValue);}
}
TextField(inputFormatters: [//使用自定義過濾器,限制中文輸入CustomizedTextInputFormatter(filterPattern: RegExp("[a-zA-Z]|[\u4e00-\u9fa5]|[0-9]"),),],
),
? ? ? ?