问题描述
如何在不使用onchange属性的情况下在Flutter中添加字符限制或限制文本字段的最大长度?
解决方法
您可以使用maxLength
的{{1}}属性来限制文本的长度,而无需使用TextField
:
onChanged()
以上内容将您的TextField(
maxLength:10
decoration: InputDecoration(
counterText: '' //hides the counterText on the bottom of the TextField
),),
TextField's
设置为10。这是maxLength的文档