如何在flutter中使用监听器添加字符限制



如何在不使用onchange属性的情况下添加字符限制或限制flutter中文本字段的最大长度?

您可以使用TextFieldmaxLength属性来限制文本的长度,而不使用onChanged():

TextField(
maxLength:10
decoration: InputDecoration(
counterText: '' //hides the counterText on the bottom of the TextField
),
),

以上内容会将您的TextField'smaxLength设置为10。这是maxLength 的文档

最新更新