如何检查文本字段在flift/dart中是否包含unicode字符?
我正在尝试为消息传递应用程序计算如何检查文本字段在flift/dart中是否包含unicode字符?,dart,flutter,Dart,Flutter,我正在尝试为消息传递应用程序计算TextField中的字符数。如果消息正文包含任何Unicode字符,则每条消息的总长度为70个字符,否则为160个。字符串。codeUnits是Unicode UTF-16代码单元的数组。 所以我想说可能是 int maxLengthOfTextField(String text){ final int maxBits = 128; List<int> unicodeSymbols = text.codeUnits.where((ch) =&
TextField
中的字符数。如果消息正文包含任何Unicode
字符,则每条消息的总长度为70个字符,否则为160个。字符串。codeUnits是Unicode UTF-16代码单元的数组。
所以我想说可能是
int maxLengthOfTextField(String text){
final int maxBits = 128;
List<int> unicodeSymbols = text.codeUnits.where((ch) => ch > maxBits ).toList();
return unicodeSymbols.length > 0 ? 160 : 70;
}
final textFieldController = TextEditingController();
TextField(
controller: textFieldController,
maxLength: maxLengthOfTextField(textFieldController.text)
);
int-maxLengthOfTextField(字符串文本){
最终整数最大位数=128;
列出unicodeSymbols=text.codeUnits.where((ch)=>ch>maxBits.toList();
返回单键符号。长度>0?160:70;
}
final textFieldController=TextEditingController();
文本字段(
控制器:textFieldController,
maxLength:maxLengthOfTextField(textFieldController.text)
);
工作起来很有魅力。谢谢:)