Search packages, repositories and app categories

mask_input_formatter cover
Package detailsv0.0.3

mask_input_formatter

TextInputFormatter for TextField and TextFormField which format the input by a given mask.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
2.6K
Likes
29
Pub points
150

Install package

flutter pub add mask_input_formatter

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter package that provides a TextInputFormatter for TextField and TextFormField to automatically format user input according to a specified mask. It helps users enter data like phone numbers, dates, or IDs in a structured way by inserting placeholders and formatting characters dynamically as they type. The formatter supports custom masks and handles backspace and cursor movement correctly across platforms. Ideal for improving input accuracy and user experience in forms requiring specific formats.

Use cases

  • Phone number input with country code
  • Date entry with separators
  • Credit card number formatting
  • Custom numeric or alphanumeric patterns
  • Form validation through input structure
  • Dynamic field formatting

Key features

  • Supports customizable masks
  • Handles backspace and cursor positioning
  • Cross-platform compatibility
  • Real-time input formatting
  • Easy integration with TextField and TextFormField
  • Flexible placeholder and separator configuration

Suitable for

  • Form inputs requiring structured data
  • Mobile and web applications with input validation
  • User-friendly data entry interfaces
  • Developers seeking simple masking solutions
  • Apps needing consistent input patterns

Considerations

  • May require careful mask definition to avoid conflicts
  • Limited support for complex dynamic masks
  • Performance impact on high-frequency input
  • Not suitable for non-text input types
  • Requires manual handling of edge cases like paste operations

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

mask_input_formatter

pub package likes popularity pub points Platform License

The package provides TextInputFormatter for TextField and TextFormField which format the input by a given mask.


Demo

Usage

  1. Add dependency.

Run this command:

With Flutter:

$ flutter pub add mask_input_formatter

or add following package in your pubspec.yaml file inside the dependencies: section.

dependencies:
  mask_input_formatter: ^0.0.3
  1. Importing the library:
import 'package:mask_input_formatter/mask_input_formatter.dart';
  1. Create a mask formatter:
MaskInputFormatter myFormatter =  MaskInputFormatter(mask: '(AA) #####');
  1. Set with TextField/TextFormField:
TextFormField(
    inputFormatters: [myFormatter],
    decoration: InputDecoration(
        hintText: "(AB) 12345",
    )
) // TextFormField

Result

// Input  --> JK75757
// Output --> (JK) 75757 set formatted text on TextField

Other Mask

You can use the mask whatever you defined in formatter:

MaskInputFormatter dateFormatter =  MaskInputFormatter(mask: '##/##/####');
// --> 26/05/2021
MaskInputFormatter phoneFormatter =  MaskInputFormatter(mask: '+# (###) ###-####');
// --> +1 (234) 567-8901
MaskInputFormatter numberFormatter =  MaskInputFormatter(mask: 'AAA-###', textAllCaps: true);
// --> XYZ-789

Check example folder for code sample

Note

In last example. --> (AAA-###)

  • 'A' character will allow only letters from A-Z.
  • '#' character will allow only numbers.
  • And other characters and symbols will be added as mask.

Contributing

Suggestions and Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Developer Team:

Amjad Jamali & team members ( Kamran Khan, Hina Hussain, Faiza Farooqui ) :tada:

License

Apache 2.0

Categories

Source repository

Projects using this package

No data available yet.