MuskeyFormatter class

An actually useful pattern matcher and field input formatter for Flutter.

Muskey is a single-file light library that's shown its usefulness throughout my projects, so I decided to share it with the world.

Supports unlimited number of masks, smart cursor positioning, and flexible customization. Clean input value and validity are available at any time.

This formatter is stateless by design, so if you want updates on validity, you need to create your own ways of doing that. For example, you can get current formatter info value inside of onChanged callback in your TextField, add a listener on your TextEditingController or any other way.

Usage:

Create an instance of this class either inside your StatefulWidget, or directly in your build method, and place it in inputFormatters list of your TextField. Provide a non-empty list of masks to work with, customize if needed.

MuskeyFormatter.countryPhoneMasks factory method is just a shortcut for an instance of this formatter to handle about 300 world phone masks on the fly.

Inheritance

Constructors

MuskeyFormatter({required List<String> masks, Map<String, Pattern>? wildcards, List<Pattern>? decorators, Map<String, String Function(String)>? charTransforms, OverflowBehavior? overflow, bool allowAutofill = false})
MuskeyFormatter.countryPhoneMasks({bool allowOverflowingInputs = true})
Convenience factory for nice formatting of about 300 phone masks.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
info CurrentMaskInfo
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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
prettyText(String input) String
A convenience function to call to autofill fields. Possible example:
toString() String
A string representation of this object.
inherited

Operators

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