maxLengthEnforcement property Null safety

MaxLengthEnforcement? maxLengthEnforcement
final

Determines how the maxLength limit should be enforced.

If MaxLengthEnforcement.none is set, additional input beyond maxLength will not be enforced by the limit.

Platform specific behaviors

Different platforms follow different behaviors by default, according to their native behavior.

MaxLengthEnforcement.enforced versus

MaxLengthEnforcement.truncateAfterCompositionEnds

Both MaxLengthEnforcement.enforced and MaxLengthEnforcement.truncateAfterCompositionEnds make sure the final length of the text does not exceed the max length specified. The difference is that MaxLengthEnforcement.enforced truncates all text while MaxLengthEnforcement.truncateAfterCompositionEnds allows composing text to exceed the limit. Allowing this "placeholder" composing text to exceed the limit may provide a better user experience on some platforms for entering ideographic characters (e.g. CJK characters) via composing on phonetic keyboards.

Some input methods (Gboard on Android for example) initiate text composition even for Latin characters, in which case the best experience may be to truncate those composing characters with MaxLengthEnforcement.enforced.

In fields that strictly support only a small subset of characters, such as verification code fields, MaxLengthEnforcement.enforced may provide the best experience.

Implementation

final MaxLengthEnforcement? maxLengthEnforcement;