MaxDigitsFormatter class
A custom TextInputFormatter that limits the number of digits a user can input.
This formatter allows only numeric input and enforces a maximum number of digits. It strips out all non-digit characters and prevents further input once the limit is reached.
Parameters:
- maxDigits: The maximum number of digits allowed in the input.
Usage:
TextField(
keyboardType: TextInputType.number,
inputFormatters: [MaxDigitsFormatter(10)],
)
This example restricts the input to a maximum of 10 digits.
- Inheritance
-
- Object
- TextInputFormatter
- MaxDigitsFormatter
Constructors
- MaxDigitsFormatter(int maxDigits)
- Creates a MaxDigitsFormatter with the specified maximum number of digits.
Properties
Methods
-
formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) → TextEditingValue -
Called when text is being typed or cut/copy/pasted in the EditableText.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited