TextFormField class
A form field wrapping a single-line text input field.
Dispatches character key presses to update the value, and provides support for placeholder text, customizable style properties, and reverse video visual cursor markers.
Example
TextFormField(
label: 'Username',
placeholder: 'Enter username',
validator: (val) => (val == null || val.isEmpty) ? 'Cannot be empty' : null,
)
- Inheritance
-
- Object
- Widget
- StatefulWidget
- FormField<
String> - TextFormField
Constructors
- TextFormField({required String label, String description = '', String? initialValue, String? validator(String?)?, bool focused = false, Style style = Style.empty, Style cursorStyle = const Style(modifiers: Modifier.reverse), String placeholder = '', Style placeholderStyle = const Style(foreground: Color(128, 128, 128))})
- Creates a TextFormField for single-line text input.
Properties
- description → String
-
Optional secondary description text for helper information.
finalinherited
- errorText ↔ String?
-
The validation error text if validation fails; otherwise,
null.getter/setter pairinherited - focused ↔ bool
-
Whether this field currently has input focus.
getter/setter pairinherited
- hasError → bool
-
Returns whether this field currently contains a validation error.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialValue → String?
-
The initial value of the field when created or reset.
finalinherited
- key → Key?
-
The optional key for this widget.
finalinherited
- label → String
-
The title label displayed for this field.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- touched ↔ bool
-
Whether this field has been focused at least once.
getter/setter pairinherited
- validator → String? Function(String?)?
-
A validation function called by FormState.validate.
Returns an error message string if invalid, or
nullif valid.finalinherited - value ↔ String?
-
The current value of the form field.
getter/setter pairinherited
Methods
-
createElement(
) → Element -
Creates an Element to manage this widget's location in the tree.
inherited
-
createState(
) → State< StatefulWidget> -
Creates the mutable state for this widget at a given location in the tree.
override
-
getIntrinsicHeight(
int width) → int -
Computes the intrinsic height of this widget under the given
widthconstraint.inherited -
getPreferredHeight(
) → int -
Calculates preferred layout height needed to render this field cleanly.
override
-
handleKeyEvent(
KeyEvent event) → void -
Handles user key inputs to update the internal value.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
render(
Buffer buffer, Rect area) → void -
Renders the widget onto the provided
bufferwithin the specifiedarea.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
validate(
) → bool -
Runs the validator callback against the current field value.
Updates errorText and returns whether the field is valid.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited