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

问题描述

如何在不使用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的文档