CupertinoTextfield
Examples#
Basic Example#
import flet as ft
def main(page: ft.Page):
page.add(
ft.TextField(
label="Material text field",
label_style=ft.TextStyle(color=ft.Colors.GREY_400),
),
ft.CupertinoTextField(
placeholder_text="Cupertino text field",
placeholder_style=ft.TextStyle(color=ft.Colors.GREY_400),
),
ft.TextField(
adaptive=True,
label="Adaptive text field",
label_style=ft.TextStyle(color=ft.Colors.GREY_400),
),
)
ft.run(main)
CupertinoTextField
#
Bases: TextField
An iOS-style text field.
adaptive
#
adaptive: bool | None = None
Enables platform-specific rendering or inheritance of adaptiveness from parent controls.
animate_align
#
animate_align: AnimationValue | None = None
Enables implicit animation of the [align
][flet.LayoutControl.] property.
More information here.
animate_margin
#
animate_margin: AnimationValue | None = None
Enables implicit animation of the [margin
][flet.LayoutControl.] property.
More information here.
animate_offset
#
animate_offset: AnimationValue | None = None
Enables implicit animation of the [offset
][flet.LayoutControl.] property.
More information here.
animate_opacity
#
animate_opacity: AnimationValue | None = None
Enables implicit animation of the [opacity
][flet.LayoutControl.] property.
More information here.
animate_position
#
animate_position: AnimationValue | None = None
Enables implicit animation of the positioning properties
([left
][flet.LayoutControl.], [right
][flet.LayoutControl.],
[top
][flet.LayoutControl.] and [bottom
][flet.LayoutControl.]).
More information here.
animate_rotation
#
animate_rotation: AnimationValue | None = None
Enables implicit animation of the [rotate
][flet.LayoutControl.] property.
More information here.
animate_scale
#
animate_scale: AnimationValue | None = None
Enables implicit animation of the [scale
][flet.LayoutControl.] property.
More information here.
aspect_ratio
#
aspect_ratio: Number | None = None
The aspect ratio of the control. It is defined as the ratio of the width to the height.
autofill_hints
#
autofill_hints: list[AutofillHint] | AutofillHint | None = (
None
)
Helps the autofill service identify the type of this text input.
More information here.
autofocus
#
autofocus: bool = False
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.
bgcolor
#
bgcolor: ColorValue | None = None
TextField background color.
Note
Will not be visible if [filled
][flet.FormFieldControl.] is False
.
border_color
#
border_color: ColorValue | None = None
The border color.
Tip
Set to [Colors.TRANSPARENT
][flet.] to invisible/hide the border.
border_width
#
border_width: Number | None = None
The width of the border in virtual pixels.
Defaults to 1
.
Tip
Set to 0
to completely remove the border.
bottom
#
bottom: Number | None = None
The distance that the child's bottom edge is inset from the bottom of the stack.
Note
Effective only if this control is a descendant of one of the following:
[Stack
][flet.] control, [Page.overlay
][flet.] list.
can_reveal_password
#
can_reveal_password: bool = False
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
can_reveal_password
/password
and suffix
are provided, then the suffix
is
not shown.
capitalization
#
capitalization: TextCapitalization | None = None
Enables automatic on-the-fly capitalization of entered text.
Defaults to TextCapitalization.NONE
.
clear_button_semantics_label
#
clear_button_semantics_label: str | None = 'Clear'
The semantic label for the clear button used by screen readers.
This will be used by screen reading software to identify the clear button widget.
clear_button_visibility_mode
#
clear_button_visibility_mode: OverlayVisibilityMode = NEVER
Defines the visibility of the clear button based on the state of text entry.
Will appear only if no suffix
is provided.
col
#
col: ResponsiveNumber = 12
If a parent of this control is a [ResponsiveRow
][flet.],
this property is used to determine
how many virtual columns of a screen this control will span.
Can be a number or a dictionary configured to have a different value for specific
breakpoints, for example col={"sm": 6}
.
This control spans the 12 virtual columns by default.
Dimensions
Breakpoint | Dimension |
---|---|
xs | <576px |
sm | ≥576px |
md | ≥768px |
lg | ≥992px |
xl | ≥1200px |
xxl | ≥1400px |
content_padding
#
content_padding: PaddingValue | None = None
The padding for the input decoration's container.
counter
#
counter: StrOrControl | None = None
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.
dense
#
dense: bool | None = None
Whether this control is part of a dense form (ie, uses less vertical space).
disabled
#
disabled: bool = False
Every control has disabled
property which is False
by default - control and all
its children are enabled.
Note
The value of this property will be propagated down to all children controls recursively.
enable_suggestions
#
enable_suggestions: bool = True
Whether to show input suggestions as the user types.
This flag only affects Android. On iOS, suggestions are tied directly to
autocorrect
, so that suggestions are only shown when autocorrect
is True
.
On Android autocorrection and suggestion are controlled separately.
Defaults to True
.
error
#
error: StrOrControl | None = None
Text that appears below the input border.
If non-null, the border's color animates to red
and the [helper
][flet.FormFieldControl.] is not shown.
error_style
#
error_style: TextStyle | None = None
The text style to use for [error
][flet.FormFieldControl.].
expand
#
Specifies whether/how this control should expand to fill available space in its parent layout.
More information here.
Note
Has effect only if the direct parent of this control is one of the following
controls, or their subclasses: [Column
][flet.], [Row
][flet.],
[View
][flet.], [Page
][flet.].
expand_loose
#
expand_loose: bool = False
Allows the control to expand along the main axis if space is available, but does not require it to fill all available space.
More information here.
Note
If expand_loose
is True
, it will have effect only if:
expand
is notNone
and- the direct parent of this control is one of the following controls, or their
subclasses: [
Column
][flet.], [Row
][flet.], [View
][flet.], [Page
][flet.].
fill_color
#
fill_color: ColorValue | None = None
Background color of TextField.
Note
Will not be visible if [filled
][flet.FormFieldControl.] is False
.
filled
#
filled: bool | None = None
If True
the decoration's container is filled with theme
[fill_color
][flet.FormFieldControl.].
If filled=None
(the default), then it is implicitly set to True
when at least
one of the following is not None
: [fill_color
][flet.FormFieldControl.],
[focused_bgcolor
][flet.FormFieldControl.],
[hover_color
][flet.FormFieldControl.] and [bgcolor
][flet.FormFieldControl.].
focused_bgcolor
#
focused_bgcolor: ColorValue | None = None
Background color in focused state.
Note
Will not be visible if [filled
][flet.FormFieldControl.] is False
.
focused_border_color
#
focused_border_color: ColorValue | None = None
Border color in focused state.
helper
#
helper: StrOrControl | None = None
Text that provides context about the input's value, such as how the value will be used.
If non-null, the text is displayed below the input decorator, in the same location
as [error
][flet.FormFieldControl.]. If a non-null
[error
][flet.FormFieldControl.] value is specified then the helper text is not
shown.
helper_style
#
helper_style: TextStyle | None = None
The text style to use for [helper
][flet.FormFieldControl.].
hint_style
#
hint_style: TextStyle | None = None
The text style to use for [hint_text
][flet.FormFieldControl.].
hint_text
#
hint_text: str | None = None
Text that suggests what sort of input the field accepts.
Displayed on top of the input when the it's empty and either
(a) [label
][flet.FormFieldControl.] is None
or (b) the input has the focus.
hover_color
#
hover_color: ColorValue | None = None
Background color of TextField when hovered.
Note
Will not be visible if [filled
][flet.FormFieldControl.] is False
.
icon
#
icon: IconDataOrControl | None = None
The icon to show before the input field and outside of the decoration's container.
image
#
image: DecorationImage | None = None
input_filter
#
input_filter: InputFilter | None = None
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.
keyboard_type
#
keyboard_type: KeyboardType = TEXT
The type of keyboard to use for editing the text.
label
#
label: StrOrControl | None = None
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 (i.e., at the same location on the screen where text may be entered in the input field). When the input field receives focus (or if the field is non-empty) the label moves above, either vertically adjacent to, or to the center of the input field.
left
#
left: Number | None = None
The distance that the child's left edge is inset from the left of the stack.
Note
Effective only if this control is a descendant of one of the following:
[Stack
][flet.] control, [Page.overlay
][flet.] list.
max_length
#
max_length: int | None = None
Limits a maximum number of characters that can be entered into TextField.
max_lines
#
max_lines: int | None = None
The maximum number of lines to show at one time, wrapping if necessary.
This affects the height of the field itself and does not limit the number of lines that can be entered into the field.
If this is 1
(the default), the text will not wrap, but will scroll horizontally
instead.
min_lines
#
min_lines: int | None = None
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 into the field.
Defaults to 1
.
offset
#
offset: OffsetValue | None = None
Applies a translation transformation before painting the control.
The translation is expressed as an Offset
scaled to the control's size.
So, Offset(x=0.25, y=0)
, for example, will result in a horizontal translation
of one quarter the width of this control.
Example
The following example displays container at 0, 0
top left corner of a stack as
transform applies -1 * 100, -1 * 100
(offset * control's size
) horizontal and
vertical translations to the control:
on_animation_end
#
on_animation_end: (
ControlEventHandler[LayoutControl] | None
) = None
Called when animation completes.
Can be used to chain multiple animations.
The data
property of the event handler argument contains the name
of the animation.
More information here.
on_blur
#
on_blur: ControlEventHandler[TextField] | None = None
Called when the control has lost focus.
on_change
#
on_change: ControlEventHandler[TextField] | None = None
Called when the typed input for the TextField has changed.
on_focus
#
on_focus: ControlEventHandler[TextField] | None = None
Called when the control has received focus.
on_submit
#
on_submit: ControlEventHandler[TextField] | None = None
Called when user presses ENTER while focus is on TextField.
opacity
#
opacity: Number = 1.0
Defines the transparency of the control.
Value ranges from 0.0
(completely transparent) to 1.0
(completely opaque
without any transparency).
padding
#
padding: PaddingValue = field(
default_factory=lambda: all(7)
)
The padding around the text entry area between the prefix
and suffix
or the clear button when clear_button_visibility_mode
is not OverlayVisibilityMode.NEVER
.
parent
#
parent: BaseControl | None
The direct ancestor(parent) of this control.
It defaults to None
and will only have a value when this control is mounted
(added to the page tree).
The Page
control (which is the root of the tree) is an exception - it always
has parent=None
.
placeholder_style
#
placeholder_style: TextStyle | None = None
The TextStyle
to use for placeholder_text
.
placeholder_text
#
placeholder_text: str | None = None
A lighter colored placeholder hint that appears on the first line of the text field when the text entry is empty.
Defaults to an empty string.
prefix
#
prefix: StrOrControl | None = None
A Control
to place on the line before the input.
It appears after the [prefix_icon
][flet.FormFieldControl.], if both are specified.
This can be used, for example, to add some padding to text that would otherwise be
specified using prefix
, or to add a custom control in front of the input.
The control's baseline is lined up with the input baseline.
prefix_icon
#
prefix_icon: IconDataOrControl | None = None
An icon that appears before the editable part of the text field, within the decoration's container.
If [prefix
][flet.FormFieldControl.] is specified and visible,
this icon will appear to its left.
prefix_style
#
prefix_style: TextStyle | None = None
The text style to use for [prefix
][flet.FormFieldControl.].
prefix_visibility_mode
#
prefix_visibility_mode: OverlayVisibilityMode = ALWAYS
read_only
#
read_only: bool = False
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.
Defaults to False
.
right
#
right: Number | None = None
The distance that the child's right edge is inset from the right of the stack.
Note
Effective only if this control is a descendant of one of the following:
[Stack
][flet.] control, [Page.overlay
][flet.] list.
rotate
#
rotate: RotateValue | None = None
Transforms this control using a rotation around its center.
The value of rotate
property could be one of the following types:
number
- a rotation in clockwise radians. Full circle360°
ismath.pi * 2
radians,90°
ispi / 2
,45°
ispi / 4
, etc.Rotate
- allows to specify rotationangle
as well asalignment
- the location of rotation center.
scale
#
scale: ScaleValue | None = None
Scales this control along the 2D plane. Default scale factor is 1.0
,
meaning no-scale.
Setting this property to 0.5
, for example, makes this control twice smaller,
while 2.0
makes it twice larger.
Different scale multipliers can be specified for x
and y
axis, by setting
Control.scale
property to an instance of Scale
class.
Either scale
or scale_x
and scale_y
could be specified, but not all of them.
shift_enter
#
shift_enter: bool = False
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.
smart_dashes_type
#
smart_dashes_type: bool = True
Whether to allow the platform to automatically format dashes.
This flag only affects iOS versions 11 and above. As an example of what this does, two consecutive hyphen characters will be automatically replaced with one en dash, and three consecutive hyphens will become one em dash.
Defaults to True
.
smart_quotes_type
#
smart_quotes_type: bool = True
Whether to allow the platform to automatically format quotes.
This flag only affects iOS. As an example of what this does, a standard vertical double quote character will be automatically replaced by a left or right double quote depending on its position in a word.
Defaults to True
.
suffix
#
suffix: StrOrControl | None = None
A Control
to place on the line after the input.
It appears before the [suffix_icon
][flet.FormFieldControl.],
if both are specified.
This can be used, for example, to add some padding to the text that would otherwise
be specified using suffix
, or to add a custom control after the input.
The control's baseline is lined up with the input baseline.
suffix_icon
#
suffix_icon: IconDataOrControl | None = None
An icon that appears after the editable part of the text field and after the
[suffix
][flet.FormFieldControl.], within the decoration's container.
suffix_style
#
suffix_style: TextStyle | None = None
The text style to use for [suffix
][flet.FormFieldControl.].
suffix_visibility_mode
#
suffix_visibility_mode: OverlayVisibilityMode = ALWAYS
text_align
#
text_align: TextAlign | None = None
How the text should be aligned horizontally.
Defaults to TextAlign.LEFT
.
text_style
#
The [TextStyle
][flet.] to use for the
text being edited.
text_vertical_align
#
text_vertical_align: VerticalAlignment | Number | None = (
None
)
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
][flet.]
Defaults to VerticalAlignment.CENTER
.
tooltip
#
tooltip: TooltipValue | None = None
The tooltip ot show when this control is hovered over.
top
#
top: Number | None = None
The distance that the child's top edge is inset from the top of the stack.
Note
Effective only if this control is a descendant of one of the following:
[Stack
][flet.] control, [Page.overlay
][flet.] list.
visible
#
visible: bool = True
Every control has visible
property which is True
by default - control is
rendered on the page. Setting visible
to False
completely prevents control (and
all its children if any) from rendering on a page canvas. Hidden controls cannot be
focused or selected with a keyboard or mouse and they do not emit any events.
build
#
Called once during control initialization to define its child controls. self.page is available in this method.