
β¨ Advanced Text Input Formatters β CodeSpark
A collection of custom TextInputFormatter
s 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
TextEditingController
listeners to detect changes in real-time. - Add a
ValueKey
when 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