Package selection guidance compiled from public package information, community data, and project usage.
Flutter Masked Text 2 is a Flutter package that enables formatted text input with customizable masks, ideal for fields like phone numbers, dates, and credit cards. It provides real-time input validation and formatting as users type, ensuring data consistency. The package supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux. It's lightweight, easy to integrate, and maintains cursor position during input. Designed for developers seeking intuitive, user-friendly input handling without sacrificing performance.
Use cases
Phone number input
Date and time formatting
Credit card number entry
Custom numeric or alphanumeric masks
Form field validation
User-friendly data entry
Key features
Real-time masking and formatting
Cursor position preservation
Support for multiple platforms
Configurable mask patterns
Built-in validation
Easy integration with TextFormField
Suitable for
Developers building forms with structured input
Apps requiring consistent data formatting
Projects needing cross-platform compatibility
UX-focused applications
Input fields with strict format requirements
Considerations
May require careful mask pattern design
Limited support for dynamic mask changes
Potential complexity with nested or conditional masks
Not suitable for unstructured text input
Performance impact with very complex masks
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
flutter_masked_text
Masked text input for flutter.
Alert
Hi guys!
Unfortunately, I'm not developing mobile anymore. This repo will not receive updates.
If you want to use default translator but override some of then, just get base from getDefaultTranslator and override what you want (here is a sample for obfuscated credit card):
var translator = MaskedTextController.getDefaultTranslator(); // get new instance of default translator.
translator.remove('*'); // removing wildcard translator.var controller = newMaskedTextController(mask: '0000 **** **** 0000', translator: translator);
controller.updateText('12345678');
print(controller.text); //1234 **** **** 5678
Change the mask in runtime
You can use the updateMask method to change the mask after the controller was created.
In some cases, you will want to validate the mask value to decide if it's allowed to input or not.
It's simple: you just need to set the beforeChange and return true or false. If you return true, it will accept the new value and will try to apply the mask. Otherwhise, it will reject the new value.
The function receives two parameters:
previous: the previous text of the controller.
next: the next text that will be masked.
var controller = newMaskedTextController(mask: '(00) 0000-0000');
controller.beforeChange = (String previous, String next) {
// my logic herereturntrue;
};
Hook: afterChange [v0.7.0+]
This function will be called after setted in the controller.