MaskTextInputFormatter constructor

MaskTextInputFormatter({
  1. String? mask,
  2. Map<String, RegExp>? filter,
  3. String? initialText,
  4. MaskAutoCompletionType type = MaskAutoCompletionType.lazy,
})

Create the mask formatter for TextField

The keys of the filter assign which character in the mask should be replaced and the values validate the entered character By default # match to the number and A to the letter

Set type for autocompletion behavior:

  • MaskAutoCompletionType.lazy (default): autocomplete unfiltered characters once the following filtered character is input. For example, with the mask "#/#" and the sequence of characters "1" then "2", the formatter will output "1", then "1/2"
  • MaskAutoCompletionType.eager: autocomplete unfiltered characters when the previous filtered character is input. For example, with the mask "#/#" and the sequence of characters "1" then "2", the formatter will output "1/", then "1/2"

Implementation

MaskTextInputFormatter({
  String? mask,
  Map<String, RegExp>? filter,
  String? initialText,
  MaskAutoCompletionType type = MaskAutoCompletionType.lazy,
}): _type = type {
  updateMask(
    mask: mask,
    filter: filter ?? {"#": RegExp('[0-9]'), "A": RegExp('[^0-9]')},
    newValue: initialText == null ? null : TextEditingValue(text: initialText, selection: TextSelection.collapsed(offset: initialText.length))
  );
}