wordpress播客主題濰坊seo招聘
? ? ? ? 由于業(yè)務(wù)需求,要限制TextField只能輸入中文,但是測(cè)試在iOS測(cè)試機(jī)發(fā)現(xiàn)自帶中文輸入法會(huì)變英文輸入問(wèn)題,安卓沒(méi)有問(wèn)題,并且只有iOS自帶輸入法有問(wèn)題,搜狗等輸入法沒(méi)問(wèn)題。我們目前使用flutter2.5.3版本,高版本應(yīng)該不存在這個(gè)問(wèn)題。
????????TextField限制中文代碼片段:
TextField(inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[a-zA-Z]|[\u4e00-\u9fa5]|[0-9]')),],
)
? ? ? ? 解決方案,自定義過(guò)濾器:
//自定義過(guò)濾器
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: [//使用自定義過(guò)濾器,限制中文輸入CustomizedTextInputFormatter(filterPattern: RegExp("[a-zA-Z]|[\u4e00-\u9fa5]|[0-9]"),),],
),
? ? ? ?