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