maxLength property

int? maxLength

The maximum number of characters (Unicode grapheme clusters) to allow in the text field.

If set, a character counter will be displayed below the field showing how many characters have been entered. If set to a number greater than 0, it will also display the maximum number allowed. If set to TextField.noMaxLength then only the current character count is displayed.

After maxLength characters have been input, additional input is ignored, unless maxLengthEnforcement is set to MaxLengthEnforcement.none.

The text field enforces the length with a LengthLimitingTextInputFormatter, which is evaluated after the supplied inputFormatters, if any.

This value must be either null, TextField.noMaxLength, or greater than 0. If null (the default) then there is no limit to the number of characters that can be entered. If set to TextField.noMaxLength, then no limit will be enforced, but the number of characters entered will still be displayed.

Whitespace characters (e.g. newline, space, tab) are included in the character count.

If maxLengthEnforcement is MaxLengthEnforcement.none, then more than maxLength characters may be entered, but the error counter and divider will switch to the decoration's InputDecoration.errorStyle when the limit is exceeded.


For a specific definition of what is considered a character, see the characters package on Pub, which is what Flutter uses to delineate characters. In general, even complex characters like surrogate pairs and extended grapheme clusters are correctly interpreted by Flutter as each being a single user-perceived character.

For instance, the character "ö" can be represented as '\u{006F}\u{0308}', which is the letter "o" followed by a composed diaeresis "¨", or it can be represented as '\u{00F6}', which is the Unicode scalar value "LATIN SMALL LETTER O WITH DIAERESIS". It will be counted as a single character in both cases.

Similarly, some emoji are represented by multiple scalar values. The Unicode "THUMBS UP SIGN + MEDIUM SKIN TONE MODIFIER", "👍🏽"is counted as a single character, even though it is a combination of two Unicode scalar values, '\u{1F44D}\u{1F3FD}'.


final int? maxLength;