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!