inputFormatters: [
  WhitelistingTextInputFormatter(RegExp(
      "[a-zA-Z]|[\u4e00-\u9fa5]|[0-9]")), //只能输入汉字或者字母或数字
  LengthLimitingTextInputFormatter(maxLength),//最大长度
],
动态修改最大字长:每输入一个中文减1
onChanged: (value) { //
  _changeMaxLimit(value);
},
/// 字符要求:5个汉字或10个英文
void _changeMaxLimit(String value) {
  maxLength = 20;
  for (int i = 0; i < value.length; i++) {
    if (value.codeUnitAt(i) > 122) {
      maxLength--;
    }
  }
}

  

相关文章:

  • 2021-07-01
  • 2021-11-19
  • 2021-12-06
  • 2022-01-30
  • 2022-12-23
猜你喜欢
  • 2021-12-12
  • 2021-11-08
  • 2021-11-28
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案