TextField
The TextField widget is an input box where users type text. Use it for search terms, names, passwords, and any other text input.
Example file: 07_Work_with_Widgets/textfield_objet.lfp
Definition and role
The TextField widget draws an area where users type text with the keyboard. When the text changes it runs onChanged, and when the user submits it runs onSubmitted. Configure decoration such as hint text and borders, the keyboard type, the maximum character count, and password obscuring.
- Category: Contents
Features
| Feature | Description |
|---|---|
| Text input | Users type characters with the keyboard, and actions run when the text changes or is submitted. |
| Input decoration | Set the look of the input box — hint text, label, borders — with decoration. |
| Input control | Set the keyboard type, maximum character count, multi-line input, read-only mode, and password obscuring. |
| Script control | Read and write the text from a script, move focus, and measure the text width. |
How to use
- Open the Contents category in the left widget palette.
- Drag and drop the TextField item onto the canvas.
- Set the look — hint text, borders, and more — in
decoration. - Connect the actions you want to run to events such as
onChanged(the text changed) oronSubmitted(the user submitted). - If needed, adjust the keyboard type (
keyboardType), the maximum character count (maxLength), and password obscuring (obscureText).
Properties
The table below lists the top-level properties you see as soon as you expand the Properties panel. Group properties like decoration and style hold more options when expanded; only the top-level entries are covered here.
| Property | Description | Default | Value / Type |
|---|---|---|---|
text | Entered text | Empty string | String |
focusNode | Focus node for the input box | Not set | Focus node |
decoration | Input decoration (hint, label, border, and more) | Not set | Input decoration |
keyboardType | Keyboard type | Not set | Keyboard type |
textInputAction | Keyboard action button (Done, Search, and so on) | Not set | Keyboard action |
textCapitalization | Automatic capitalization | none | none, words, sentences, characters |
style | Text style | Not set | Text style |
strutStyle | Strut style, including line height | Not set | Strut style |
textAlign | Text alignment | start | left, right, center, justify, start, end |
textAlignVertical | Vertical alignment position | Not set | Number (-1.0 to 1.0) |
textDirection | Text direction | Not set | rtl, ltr |
readOnly | Read-only (no input allowed) | Off (false) | True / False |
howCursor | How the cursor is shown — has no effect in the current version. | Off (false) | True / False |
showCursor | Whether to show the cursor | Not set | True / False |
autofocus | Focus automatically when the screen opens | Off (false) | True / False |
obscuringCharacter | Character shown in place of obscured text | • | Character |
obscureText | Obscure the input (password) | Off (false) | True / False |
autocorrect | Autocorrect | On (true) | True / False |
smartDashesType | Smart dashes input | Not set | disabled, enabled |
smartQuotesType | Smart quotes input | Not set | disabled, enabled |
enableSuggestions | Input suggestions | On (true) | True / False |
maxLines | Maximum number of lines | Not set (1 line) | Integer |
minLines | Minimum number of lines | Not set | Integer |
expands | Expand to fill the parent's height | Off (false) | True / False |
maxLength | Maximum number of characters | Not set (no limit) | Integer |
maxLengthEnforcement | How input beyond the maximum length is handled | Not set | none, enforced, truncateAfterCompositionEnds |
inputFormatters | List of input format restrictions | Not set | List |
enabled | Whether the field is enabled | Not set (enabled) | True / False |
cursorWidth | Cursor thickness | 2 | Number |
cursorHeight | Cursor height | Not set | Number |
cursorRadius | Corner radius of the cursor | Not set | Radius |
cursorColor | Cursor color | Not set | Color |
selectionHeightStyle | How the height of the selection area is measured | tight | tight, max, includeLineSpacingMiddle, includeLineSpacingTop, includeLineSpacingBottom, strut |
selectionWidthStyle | How the width of the selection area is measured | tight | tight, max |
keyboardAppearance | Keyboard brightness theme | Not set | dark, light |
scrollPadding | Padding kept clear while scrolling | 20 | Insets |
dragStartBehavior | Drag start behavior | start | start, down |
enableInteractiveSelection | Allow selection (copy, paste, and so on) | Not set | True / False |
mouseCursor | Mouse cursor | Not set | Cursor |
scrollController | Scroll controller | Not set | Scroll controller |
scrollPhysics | How scrolling behaves | Not set | Scroll physics |
autofillHints | List of autofill hints | Not set (empty list) | List |
clipBehavior | How content outside the bounds is clipped | hardEdge | none, hardEdge, antiAlias, antiAliasWithSaveLayer |
restorationId | State restoration ID | Not set | String |
scribbleEnabled | Enable Scribble (pen input) | On (true) | True / False |
enableIMEPersonalizedLearning | Enable IME personalized learning | On (true) | True / False |
Notes and tips
For a password field, turn on obscureText and, if needed, change the mask character with obscuringCharacter.
For multi-line input, raise maxLines (and minLines), or turn on expands to fill the parent's height.
Learn more
For the full set of Widget Control (Property, Method, Event) you can drive from a script, visit TextField Widget Control.