mask_text_input_formatter

Last updated:

0 purchases

mask_text_input_formatter Image
mask_text_input_formatter Images
Add to Cart

Description:

mask text input formatter

mask_text_input_formatter #

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

Example #
Check 'example' folder for code sample

Usage #


Follow the install guide


Import the library:


import 'package:mask_text_input_formatter/mask_text_input_formatter.dart';
copied to clipboard

Create mask formatter:

var maskFormatter = new MaskTextInputFormatter(
mask: '+# (###) ###-##-##',
filter: { "#": RegExp(r'[0-9]') },
type: MaskAutoCompletionType.lazy
);
copied to clipboard

Set it to text field:

TextField(inputFormatters: [maskFormatter])
copied to clipboard
Get value #
Get masked text:
print(maskFormatter.getMaskedText()); // -> "+0 (123) 456-78-90"
copied to clipboard
Get unmasked text:
print(maskFormatter.getUnmaskedText()); // -> 01234567890
copied to clipboard
Change the mask #
You can use the updateMask method to change the mask after the formatter was created:
var textEditingController = TextEditingController(text: "12345678");
var maskFormatter = new MaskTextInputFormatter(mask: '####-####', filter: { "#": RegExp(r'[0-9]') });

TextField(controller: textEditingController, inputFormatters: [maskFormatter]) // -> "1234-5678"

textEditingController.value = maskFormatter.updateMask(mask: "##-##-##-##"); // -> "12-34-56-78"
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.