TextField class
An interactive single-line or multi-line text input field.
It coordinates keyboard inputs to mutate text values, maintains cursor state and scroll offsets, and supports undo/redo history.
Keyboard Hotkey Reference Table
| Keyboard Shortcut | Action | Description |
|---|---|---|
Ctrl + W |
deleteWordLeft |
Delete the word behind the cursor. |
Ctrl + D / Ctrl + Del |
deleteWordRight |
Delete the word in front of the cursor. |
Ctrl + Z / Alt + Z |
undo |
Revert the last text mutation. |
Ctrl + Y / Alt + Y |
redo |
Reapply a previously reverted mutation. |
Ctrl + Left |
moveWordLeft |
Move cursor one word backward. |
Ctrl + Right |
moveWordRight |
Move cursor one word forward. |
Home / Ctrl + Shift + Left |
moveToLineStart |
Move cursor to the beginning of the line. |
End / Ctrl + Shift + Right |
moveToLineEnd |
Move cursor to the end of the line. |
Example Usage
final controller = TextEditingController(text: 'Edit me');
TextField(
controller: controller,
multiline: false,
placeholder: 'Type here...',
focused: true,
);
Properties and Settings
| Property | Type | Description |
|---|---|---|
controller |
TextEditingController | Holds the text value and selection state. |
multiline |
bool | Enable multi-line input and wraps lines. |
style |
Style | Formatting attributes for the input text. |
cursorStyle |
Style | Highlighting style for the cursor cell. |
placeholder |
String | Ghost hint text displayed when field is empty. |
placeholderStyle |
Style | Style of the placeholder hint text. |
focused |
bool | Determines if cursor is drawn and keys are processed. |
customShortcuts |
Map? | Custom key mappings for input actions. |
- Inheritance
-
- Object
- Widget
- StatefulWidget
- TextField
Constructors
-
TextField({Key? key, String initialText = '', String? value, int? cursorPosition, TextEditingController? controller, bool multiline = false, Style style = Style.empty, Style cursorStyle = const Style(modifiers: Modifier.reverse), String placeholder = '', Style placeholderStyle = const Style(foreground: Color(128, 128, 128)), bool focused = true, Map<
TextFieldShortcut, TextFieldAction> ? customShortcuts}) - Creates a TextField.
Properties
- controller → TextEditingController
-
The text editing controller.
final
- cursorColumn ↔ int
-
Gets the cursor column.
getter/setter pair
- cursorLine ↔ int
-
Gets the cursor line.
getter/setter pair
- cursorPosition ↔ int
-
Gets the cursor column.
getter/setter pair
- cursorStyle ↔ Style
-
Highlighting style for the cursor cell.
getter/setter pair
-
customShortcuts
→ Map<
TextFieldShortcut, TextFieldAction> ? -
Custom key mappings for input actions.
final
- focused ↔ bool
-
Determines if cursor is drawn and keys are processed.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
The optional key for this widget.
finalinherited
- multiline → bool
-
Whether the field supports multiple lines.
final
- placeholder → String
-
Ghost hint text displayed when field is empty.
final
- placeholderStyle ↔ Style
-
Style of the placeholder hint text.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollOffset ↔ int
-
Vertical scroll offset.
getter/setter pair
- style ↔ Style
-
Formatting attributes for the input text.
getter/setter pair
- value ↔ String
-
Gets the complete value of the text field.
getter/setter pair
Methods
-
adjustScroll(
int viewportHeight) → void - Adjusts the scroll offset based on the viewport height.
-
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.override -
handleKeyEvent(
KeyEvent event) → void - Handles key events to update the text area value and cursor position.
-
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
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
defaultShortcuts
→ Map<
TextFieldShortcut, TextFieldAction> -
The default key bindings mapping shortcuts to actions.
final