TextField class

A text input widget supporting single-line and multi-line editing.

This wraps TextInputModel and integrates with FocusController so keyboard input is handled only when focused. Mouse presses are handled inside the input zone for cursor positioning and selection.

For multi-line editing, set multiline to true and provide a width for soft-wrapping. Optionally set maxLines to limit the visible height and enable vertical scrolling.

Inheritance

Constructors

TextField({TextInputModel? model, TextFieldController? controller, String? prompt, String? placeholder, int? width, EchoMode? echoMode, String? echoCharacter, int? charLimit, bool? showSuggestions, List<String>? suggestions, bool? collapseLargePaste, int? collapsedPasteMinChars, int? collapsedPasteMinLines, bool? useVirtualCursor, TextInputStyles? styles, TextInputKeyMap? keyMap, CursorModel? cursor, TextChangedCallback? onChanged, FocusController? focusController, String? focusId, bool autofocus = false, bool enabled = true, bool multiline = false, int maxLines = 0, int mouseXOffset = 0, String? zoneId, Key? key})

Properties

autofocus bool
Whether to request focus on first build.
final
charLimit int?
Maximum characters allowed (0 = unlimited).
final
children List<Widget>
Child widgets that receive forwarded messages.
no setterinherited
collapsedPasteMinChars int?
Minimum paste size in characters to collapse.
final
collapsedPasteMinLines int?
Minimum paste size in lines to collapse.
final
collapseLargePaste bool?
Whether to collapse large pasted content into a compact reference token.
final
controller TextFieldController?
Optional controller to hold input state.
final
cursor CursorModel?
Optional cursor model. Defaults to a static cursor.
final
debugRenderObjectPassthrough bool
Whether this widget is intentionally transparent to render-object layouts.
no setterinherited
echoCharacter String?
Character to show in password mode.
final
echoMode EchoMode?
Echo mode for displaying text.
final
enabled bool
Whether input is enabled.
final
focusable bool
Whether this widget can receive keyboard focus.
no setterinherited
focusController FocusController?
Optional focus controller for focus coordination.
final
focusId String?
Optional focus identifier.
final
hashCode int
The hash code for this object.
no setterinherited
id String
Unique identifier for this widget.
no setterinherited
key Key?
Key for preserving widget identity.
finalinherited
keyMap TextInputKeyMap?
Optional key bindings.
final
maxLines int
Maximum visible height in rows (0 = unlimited growth).
final
model TextInputModel?
Optional model to use for input behavior.
final
mouseXOffset int
Optional horizontal offset correction (in cells) applied to mouse hit coordinates before they are forwarded to TextInputModel.
final
multiline bool
Whether to enable multi-line editing.
final
onChanged TextChangedCallback?
Called when the value changes.
final
placeholder String?
Placeholder text when empty.
final
prompt String?
Prompt displayed before input.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showSuggestions bool?
Whether to show suggestions.
final
styles TextInputStyles?
Styles used for focused/blurred input.
final
suggestions List<String>?
Suggestions for autocomplete.
final
theme Theme
Access the current theme.
no setterinherited
useVirtualCursor bool?
Whether to render a virtual cursor.
final
width int?
Display width for horizontal scrolling (0 = unlimited).
final
zoneId String?
Optional zone id for mouse interactions.
final

Methods

buildCachedView<T>(T builder(), Object? cacheKey) → T
Returns a cached view if the cache key matches.
inherited
createState() State<StatefulWidget>
Creates the mutable State associated with this widget.
override
handleInit() Cmd?
Override this instead of init for widget-specific initialization.
inherited
handleIntercept(Msg msg) → (Widget, Cmd?)
Override this to handle messages before they reach children.
inherited
handleUpdate(Msg msg) → (Widget, Cmd?)
Override this to handle messages specific to this widget.
inherited
init() Cmd?
Called once when the widget is first mounted.
inherited
invalidateCachedView() → void
Clears any cached view for this widget.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
update(Msg msg) → (Model, Cmd?)
Handles messages by forwarding to children then calling handleUpdate.
inherited
view() Object
Renders the widget to a string or View.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited