maxLengthEnforcement property Null safety
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.
- Android, Windows: MaxLengthEnforcement.enforced. The native behavior of these platforms is enforced. The composing will be handled by the IME while users are entering CJK characters.
- iOS: MaxLengthEnforcement.truncateAfterCompositionEnds. iOS has no default behavior and it requires users implement the behavior themselves. Allow the composition to exceed to avoid breaking CJK input.
- Web, macOS, linux, fuchsia: MaxLengthEnforcement.truncateAfterCompositionEnds. These platforms allow the composition to exceed by default.
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;