How to add character limit using listener in flutter

Viewed 173

How to add character limit or restrict max length of the text field in flutter without using onchange attribute?

1 Answers

You could use the maxLength property of the TextField to limit the length of the text without using onChanged():

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

The above will set your TextField's maxLength to 10. Here is the documentation for maxLength

Related