CapitalizeFirstLetterFormatter class
A text input formatter that capitalizes the first letter of the input.
Automatically converts the first character of the text field input to uppercase while leaving the rest of the text unchanged. Useful for names, titles, and sentences that should start with a capital letter.
The formatter is applied in real-time as the user types, ensuring the first character is always capitalized without modifying subsequent characters.
Example:
TextField(
inputFormatters: [
CapitalizeFirstLetterFormatter(),
],
decoration: InputDecoration(
hintText: 'Enter your name',
),
)
// User types: "john" → Displays: "John"
// User types: "mary smith" → Displays: "Mary smith"
Note: This only capitalizes the very first character. If you need to capitalize the first letter of each word, use a different formatter.
See also:
- TextInputFormatter for creating custom input formatters
- Inheritance
-
- Object
- TextInputFormatter
- CapitalizeFirstLetterFormatter
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) → TextEditingValue -
Formats the text edit update by capitalizing the first character.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited