MaskedTextInputFormatter class
A custom TextInputFormatter for applying a mask to text input.
This class formats text input dynamically according to the provided mask.
It replaces each # character in the mask with corresponding digit from the input,
and keeps other character (e.g., spaces, dashes, parentheses) as static.
Parameters:
- mask : A string defining the desired format.
- Use
#as placeholder for digits. - Static characters in the mask (e.g.,
-,(,)) are retained in the formatted output.
- Use
Examples:
final formatter = MaskedTextInputFormatter(mask: '(###) ###-####'); // Input: "1234567890" // Output: "(123) 456-7890"
final formatter = MaskedTextInputFormatter(mask: '####-####-####-####'); // Input: "4111111111111111" // Output: "4111-1111-1111-1111"
- Inheritance
-
- Object
- TextInputFormatter
- MaskedTextInputFormatter
Constructors
- MaskedTextInputFormatter({required String mask})
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