Banner

✨ 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 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!