โจ Advanced Text Input Formatters โ CodeSpark
A collection of custom TextInputFormatters and helper utilities designed to enhance and control user input in Flutter apps. Each formatter is easy to plug into your TextField or TextFormField, and most come with clean utility methods for validation and behavior tuning.
๐ PAN Card Input Formatter (Smart Keyboard Switch)
Enforces Indian PAN card format: ABCDE1234F
โ๏ธ Automatically uppercases letters
โ๏ธ Dynamically switches keyboard type (text โ number โ text)
โ๏ธ Optional validator provided
final TextEditingController _controller = TextEditingController();
final keyboardType = PanCardInputHelper.getKeyboardType(_controller.text);
TextFormField(
key: ValueKey(keyboardType), // Forces rebuild to change keyboard
controller: _controller,
decoration: const InputDecoration(
labelText: 'Enter PAN Card Number',
border: OutlineInputBorder(),
),
autofocus: true,
keyboardType: keyboardType,
inputFormatters: [PanCardInputHelper.formatter],
validator: (val) => PanCardInputHelper.validate(val ?? ''),
onChanged: (value) => setState(() {}), // Required to trigger rebuild
);
๐ง Formatters Included
โ Typing Delay Formatter
Mimics human-like typing latency by simulating delayed input.
TypingDelayController typingController = TypingDelayController();
TextField(
controller: typingController,
onChanged: (value) {
if (!typingController.text.endsWith(value.characters.last)) {
typingController.typeCharacter(value.characters.last);
}
},
)
๐ข Digits Only Formatter
Allows only numeric digits (0โ9).
TextField(
inputFormatters: [DigitsOnlyFormatter()],
)
๐ Input Mirror Formatter
Reverses the text as you type.
Input: hello โ Output: olleh
TextField(
inputFormatters: [InputMirrorFormatter()],
)
๐ซ Prevent Repeat Characters
Blocks immediate duplicate characters.
Input: aaabbb โ Output: ab
TextField(
inputFormatters: [PreventRepeatCharactersFormatter()],
)
โ๏ธ Block Clipboard Access
Disables pasting into the field.
TextField(
inputFormatters: [BlockClipboardFormatter()],
)
๐ช Only Palindromes Allowed
Allows only valid palindromes.
TextField(
inputFormatters: [PalindromeOnlyFormatter()],
)
Allowed: madam, racecar
Blocked: hello
๐ก Only Alphabets
Strips everything but AโZ and aโz.
TextField(
inputFormatters: [OnlyAlphabetsFormatter()],
)
Input: abc123@# โ Output: abc
๐ซ CamelCase Formatter
Converts input to camelCase.
TextField(
inputFormatters: [CamelCaseInputFormatter()],
)
Input: hello world โ Output: helloWorld
๐ Snake_case Formatter
Formats input as snake_case.
TextField(
inputFormatters: [SnakeCaseInputFormatter()],
)
Input: hello world โ Output: hello_world
โ Kebab-case Formatter
Formats input as kebab-case.
TextField(
inputFormatters: [KebabCaseInputFormatter()],
)
Input: hello world โ Output: hello-world
โ Replace Whitespace With Underscores
Replaces all spaces with underscores.
TextField(
inputFormatters: [WhitespaceToUnderscoreFormatter()],
)
Input: hello world flutter โ Output: hello_world_flutter
๐ซ Prevent Multiple Consecutive Spaces
Ensures only a single space between words.
TextField(
inputFormatters: [SingleSpaceFormatter()],
)
Input: hello world โ Output: hello world
๐งช Usage Tips
- Combine multiple formatters for strict control.
- Use
.validate()utilities where available. - Attach
TextEditingControllerlisteners to detect changes in real-time. - Add a
ValueKeywhen dynamically changing keyboardType (e.g. PAN formatter).
๐จโ๐ป Maintainer
Made with ๐ by Katayath Sai Kiran ๐ฌ Contributions, stars, and suggestions welcome!
Libraries
- advanced_text_input_formatters_codespark
- controllers/typing_delay_controller
- formatters/camel_case_formatter
- formatters/digits_only_formatter
- formatters/kebab_case_formatter
- formatters/mirror_text_formatter
- formatters/no_paste_formatter
- formatters/no_repeat_characters_formatter
- formatters/only_alphabets_formatter
- formatters/palindrome_only_formatter
- formatters/pan_card_formatter
- formatters/prevent_multiple_spaces_formatter
- formatters/replace_whitespace_with_underscore_formatter
- formatters/snake_case_formatter