advanced_text_input_formatters_codespark 0.0.4
advanced_text_input_formatters_codespark: ^0.0.4 copied to clipboard
A Flutter package with advanced custom TextInputFormatters—simulate typing, block clipboard, allow only palindromes, enforce naming conventions and more.
✨ 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!