MaxLengthEnforcement enum Null safety

MaxLengthEnforcement.enforced versus


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.

See also:


enforced → const MaxLengthEnforcement

Keep the length of the text input from exceeding the max length even when the text has an unfinished composing region.

const MaxLengthEnforcement(1)
none → const MaxLengthEnforcement

No enforcement applied to the editing value. It's possible to exceed the max length.

const MaxLengthEnforcement(0)
truncateAfterCompositionEnds → const MaxLengthEnforcement

Users can still input text if the current value is composing even after reaching the max length limit. After composing ends, the value will be truncated.

const MaxLengthEnforcement(2)
values → const List<MaxLengthEnforcement>

A constant List of the values in this enum, in order of their declaration.

const List<MaxLengthEnforcement>


hashCode int
The hash code for this object. [...]
read-only, inherited
index int

The integer index of this enum.

runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]