FilteringTextInputFormatter class Null safety

A TextInputFormatter that prevents the insertion of characters matching (or not matching) a particular pattern, by replacing the characters with the given replacementString.

Instances of filtered characters found in the new TextEditingValues will be replaced by the replacementString which defaults to the empty string, and the current TextEditingValue.selection and TextEditingValue.composing region will be adjusted to account for the replacement.

This formatter is typically used to match potentially recurring Patterns in the new TextEditingValue. It never completely rejects the new TextEditingValue and falls back to the current TextEditingValue when the given filterPattern fails to match. Consider using a different TextInputFormatter such as:

TextInputFormatter.withFunction((oldValue, newValue) => regExp.hasMatch(newValue.text) ? newValue : oldValue)

for accepting/rejecting new input based on a predicate on the full string. As an example, FilteringTextInputFormatter typically shouldn't be used with RegExps that contain positional matchers (^ or $) since these patterns are usually meant for matching the whole string.

Inheritance

Constructors

FilteringTextInputFormatter(Pattern filterPattern, {required bool allow, String replacementString = ''})
Creates a formatter that replaces banned patterns with the given replacementString.
FilteringTextInputFormatter.allow(Pattern filterPattern, {String replacementString = ''})
Creates a formatter that only allows characters matching a pattern.
FilteringTextInputFormatter.deny(Pattern filterPattern, {String replacementString = ''})
Creates a formatter that blocks characters matching a pattern.

Properties

allow bool
Whether the pattern is an allow list or not.
final
filterPattern Pattern
A Pattern to match or replace in incoming TextEditingValues.
final
hashCode int
The hash code for this object.
read-onlyinherited
replacementString String
String used to replace banned patterns.
final
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

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 non-existent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

digitsOnly TextInputFormatter
A TextInputFormatter that takes in digits [0-9] only.
final
singleLineFormatter TextInputFormatter
A TextInputFormatter that forces input to be a single line.
final