TextField
A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard.Properties
Basic Properties
Current value of the TextField.
Optional text that describes the input field. When the input field is empty and unfocused, the label is displayed on top of the input field. When the input field receives focus (or if the field is non-empty) the label moves above the input field.
Text that suggests what sort of input the field accepts. Displayed on top of the input when it’s empty and either the label is None or the input has focus.
Text that provides context about the input’s value, such as how the value will be used. Displayed below the input decorator. If a non-null
error value is specified then the helper text is not shown.The icon to show before the input field and outside of the decoration’s container.
Text Configuration
Text size in virtual pixels.
The TextStyle to use for the text being edited.
How the text should be aligned horizontally.
Defines how the text should be aligned vertically. Value can either be a number ranging from
-1.0 (topmost location) to 1.0 (bottommost location) or of type VerticalAlignment.Input Behavior
The type of keyboard to use for editing the text. Options include:
TEXT, MULTILINE, NUMBER, PHONE, DATETIME, EMAIL, URL, VISIBLE_PASSWORD, NAME, STREET_ADDRESS, WEB_SEARCH, TWITTER.Whether this field can contain multiple lines of text.
The minimum number of lines to occupy when the content spans fewer lines. This affects the height of the field itself and does not limit the number of lines that can be entered.Must be positive and not exceed
max_lines when both are set.The maximum number of lines to show at one time, wrapping if necessary. If this is
1, the text will not wrap, but will scroll horizontally instead.Must be positive and not less than min_lines.Limits a maximum number of characters that can be entered into TextField. Must be either
-1 or a positive integer.Whether to hide the text being edited.
Displays a toggle icon button that allows revealing the entered password. Is shown if both
password and can_reveal_password are True. The icon is displayed in the same location as suffix and in case both are provided, then the suffix is not shown.Whether the text can be changed. When this is set to
True, the text cannot be modified by any shortcut or keyboard operation. The text is still selectable.Changes the behavior of
Enter button in multiline TextField to be chat-like, i.e. new line can be added with Shift+Enter and pressing just Enter fires on_submit event.Whether to intercept Arrow-Up and Arrow-Down when this field has focus. When set to
True, pressing those keys does not move the caret to the beginning or end of the text respectively.Text Formatting
Enables automatic on-the-fly capitalization of entered text. Options:
CHARACTERS, WORDS, SENTENCES, NONE.Whether to enable autocorrection.
Whether to show input suggestions as the user types. This flag only affects Android. On iOS, suggestions are tied directly to
autocorrect.Whether to allow the platform to automatically format dashes. This flag only affects iOS versions 11 and above.
Whether to allow the platform to automatically format quotes. This flag only affects iOS.
Input Filtering
Provides as-you-type filtering/validation. Similar to the
on_change callback, the input filters are not applied when the content of the field is changed programmatically.Selection
Represents the current text selection or caret position in the field. Setting this property visually updates the field’s selection and triggers the
on_selection_change event. To ensure the selection is visible and the event is fired, the text field must be focused.Cursor Styling
Whether the field’s cursor is to be shown.
The color of TextField cursor.
Sets cursor width.
Sets cursor height.
Sets cursor radius.
The color of TextField selection.
Visual Styling
Text color.
TextField background color. Will not be visible if
filled is False.Border around input. Options:
NONE, OUTLINE, UNDERLINE.The border radius of the input decoration.
The width of the border in virtual pixels. Set to
0 to completely remove the border.The border color. Set to
Colors.TRANSPARENT to invisible/hide the border.The text’s color when focused.
Background color in focused state. Will not be visible if
filled is False.Border width in focused state.
Border color in focused state.
If
True the decoration’s container is filled with theme fill_color. If None (default), it is implicitly set to True when at least one color property is not None.Background color of TextField. Will not be visible if
filled is False.Background color of TextField when hovered. Will not be visible if
filled is False.Decorations
A Control to place on the line before the input. This can be used to add padding or a custom control in front of the input.
An icon that appears before the editable part of the text field, within the decoration’s container.
A Control to place on the line after the input. This can be used to add padding or a custom control after the input.
An icon that appears after the editable part of the text field and after the
suffix, within the decoration’s container.A Control to place below the line as a character count. If
None or an empty string then nothing will appear in the counter’s location.Text that appears below the input border. If non-null, the border’s color animates to red and the
helper is not shown.Padding and Layout
The padding for the input decoration’s container.
Whether this control is part of a dense form (i.e., uses less vertical space).
Other Properties
True if the control will be selected as the initial focus. If there is more than one control on a page with autofocus set, then the first one added to the page will get focus.
Helps the autofill service identify the type of this text input.
Defines how the content is clipped.
The mouse cursor to use when hovering over this control.
Events
Called when the typed input for the TextField has changed.
Called when the text selection or caret position changes. This can be triggered either by user interaction or programmatically through the
selection property.Called when user presses ENTER while focus is on TextField.
Called when the control has received focus.
Called when the control has lost focus.
Methods
Request focus for this control.Example:
Helper Classes
InputFilter
An input filter that uses a regular expression to allow or deny certain patterns in the input. Properties:regex_string(str): A regular expression pattern for the filter. Recommended to use raw strings (e.g.,r"pattern").allow(bool): Whether to allow or deny/block the matched patterns. Default:True.replacement_string(str): A string used to replace banned/denied patterns. Default: empty string.multiline(bool): Whether the regexp matches multiple lines. Default:False.case_sensitive(bool): Whether the regular expression is case sensitive. Default:True.unicode(bool): Whether the regular expression uses Unicode mode. Default:False.dot_all(bool): Whether"."matches line terminators. Default:False.