Skip to content

Text 继承自:LayoutControl, Control, BaseControl

显示文本。

它由两个来源组合而成,共同生成最终文本: value 和 spans。

示例:

python
ft.Text("Hello from Flet!", size=24, weight=ft.FontWeight.W_600)

示例 ​

python
import flet as ft


def main(page: ft.Page):
    page.title = "Text custom styles"
    page.scroll = ft.ScrollMode.ADAPTIVE

    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text("Size 10", size=10),
                    ft.Text(
                        "Size 30, Italic",
                        size=30,
                        color=ft.Colors.PINK_600,
                        italic=True,
                    ),
                    ft.Text(
                        value="Size 40, w100",
                        size=40,
                        color=ft.Colors.WHITE,
                        bgcolor=ft.Colors.BLUE_600,
                        weight=ft.FontWeight.W_100,
                    ),
                    ft.Text(
                        value="Size 50, Normal",
                        size=50,
                        color=ft.Colors.WHITE,
                        bgcolor=ft.Colors.ORANGE_800,
                        weight=ft.FontWeight.NORMAL,
                    ),
                    ft.Text(
                        value="Size 60, Bold, Italic",
                        size=50,
                        color=ft.Colors.WHITE,
                        bgcolor=ft.Colors.GREEN_700,
                        weight=ft.FontWeight.BOLD,
                        italic=True,
                    ),
                    ft.Text(
                        value="Size 70, w900, selectable",
                        size=70,
                        weight=ft.FontWeight.W_900,
                        selectable=True,
                    ),
                    ft.Text(
                        value="Limit long text to 1 line with ellipsis",
                        theme_style=ft.TextThemeStyle.HEADLINE_SMALL,
                    ),
                    ft.Text(
                        value=(
                            "Proin rutrum, purus sit amet elementum volutpat, nunc "
                            "lacus vulputate orci, cursus ultrices neque dui quis "
                            "purus. Ut ultricies purus nec nibh bibendum, eget "
                            "vestibulum metus various. Duis convallis maximus justo, "
                            "eu rutrum libero maximus id. Donec ullamcorper arcu in "
                            "sapien molestie, non pellentesque tellus pellentesque. "
                            "Nulla nec tristique ex. Maecenas euismod nisl enim, a "
                            "convallis arcu laoreet at. Ut at tortor finibus, rutrum "
                            "massa sit amet, pulvinar velit. Phasellus diam lorem, "
                            "viverra vitae leo vitae, consequat suscipit lorem."
                        ),
                        max_lines=1,
                        overflow=ft.TextOverflow.ELLIPSIS,
                    ),
                    ft.Text(
                        value="Limit long text to 2 lines and fading",
                        theme_style=ft.TextThemeStyle.HEADLINE_SMALL,
                    ),
                    ft.Text(
                        value=(
                            "Lorem ipsum dolor sit amet, consectetur adipiscing "
                            "elit. Curabitur quis nibh vitae purus consectetur "
                            "facilisis sed vitae ipsum. Quisque faucibus sed nulla "
                            "placerat sagittis. Phasellus condimentum risus vitae "
                            "nulla vestibulum auctor. Curabitur scelerisque, nibh "
                            "eget imperdiet consequat, odio ante tempus diam, sed "
                            "volutpat nisl erat eget turpis. Sed viverra, diam sit "
                            "amet blandit vulputate, mi tellus dapibus lorem, vitae "
                            "vehicula diam mauris placerat diam. Morbi sit amet "
                            "pretium turpis, et consequat ligula. Nulla velit sem, "
                            "suscipit sit amet dictum non, tincidunt sed nulla. "
                            "Aenean pellentesque odio porttitor sagittis aliquam. "
                            "Name various at metus vitae vulputate. Praesent "
                            "faucibus nibh lorem, eu pretium dolor dictum nec. "
                            "Phasellus eget dui laoreet, viverra magna vitae, "
                            "pellentesque diam."
                        ),
                        max_lines=2,
                    ),
                    ft.Text(
                        value="Limit the width and height of long text",
                        theme_style=ft.TextThemeStyle.HEADLINE_SMALL,
                    ),
                    ft.Text(
                        value=(
                            "Lorem ipsum dolor sit amet, consectetur adipiscing "
                            "elit. Curabitur quis nibh vitae purus consectetur "
                            "facilisis sed vitae ipsum. Quisque faucibus sed nulla "
                            "placerat sagittis. Phasellus condimentum risus vitae "
                            "nulla vestibulum auctor. Curabitur scelerisque, nibh "
                            "eget imperdiet consequat, odio ante tempus diam, sed "
                            "volutpat nisl erat eget turpis. Sed viverra, diam sit "
                            "amet blandit vulputate, mi tellus dapibus lorem, vitae "
                            "vehicula diam mauris placerat diam. Morbi sit amet "
                            "pretium turpis, et consequat ligula. Nulla velit sem, "
                            "suscipit sit amet dictum non, tincidunt sed nulla. "
                            "Aenean pellentesque odio porttitor sagittis aliquam. "
                            "Name various at metus vitae vulputate. Praesent "
                            "faucibus nibh lorem, eu pretium dolor dictum nec. "
                            "Phasellus eget dui laoreet, viverra magna vitae, "
                            "pellentesque diam."
                        ),
                        width=700,
                        height=100,
                    ),
                ],
            ),
        ),
    )


if __name__ == "__main__":
    ft.run(main)
python
import flet as ft


def main(page: ft.Page):
    page.title = "Text theme styles"
    page.scroll = ft.ScrollMode.ADAPTIVE

    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text(
                        "Display Large",
                        theme_style=ft.TextThemeStyle.DISPLAY_LARGE,
                    ),
                    ft.Text(
                        "Display Medium",
                        theme_style=ft.TextThemeStyle.DISPLAY_MEDIUM,
                    ),
                    ft.Text(
                        "Display Small",
                        theme_style=ft.TextThemeStyle.DISPLAY_SMALL,
                    ),
                    ft.Text(
                        "Headline Large",
                        theme_style=ft.TextThemeStyle.HEADLINE_LARGE,
                    ),
                    ft.Text(
                        "Headline Medium",
                        theme_style=ft.TextThemeStyle.HEADLINE_MEDIUM,
                    ),
                    ft.Text(
                        "Headline Small",
                        theme_style=ft.TextThemeStyle.HEADLINE_SMALL,
                    ),
                    ft.Text("Title Large", theme_style=ft.TextThemeStyle.TITLE_LARGE),
                    ft.Text("Title Medium", theme_style=ft.TextThemeStyle.TITLE_MEDIUM),
                    ft.Text("Title Small", theme_style=ft.TextThemeStyle.TITLE_SMALL),
                    ft.Text("Label Large", theme_style=ft.TextThemeStyle.LABEL_LARGE),
                    ft.Text(
                        "Label Medium",
                        theme_style=ft.TextThemeStyle.LABEL_MEDIUM,
                    ),
                    ft.Text("Label Small", theme_style=ft.TextThemeStyle.LABEL_SMALL),
                    ft.Text("Body Large", theme_style=ft.TextThemeStyle.BODY_LARGE),
                    ft.Text("Body Medium", theme_style=ft.TextThemeStyle.BODY_MEDIUM),
                    ft.Text("Body Small", theme_style=ft.TextThemeStyle.BODY_SMALL),
                ],
            ),
        ),
    )


if __name__ == "__main__":
    ft.run(main)
python
import flet as ft


def main(page: ft.Page):
    page.fonts = {
        "RobotoSlab": "https://github.com/google/fonts/raw/main/apache/robotoslab/RobotoSlab%5Bwght%5D.ttf"
    }

    def handle_slider_change(e):
        text.weight = f"w{int(e.control.value)}"  # noqa
        text.update()

    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    text := ft.Text(
                        "This is rendered with Roboto Slab",
                        size=30,
                        font_family="RobotoSlab",
                        weight=ft.FontWeight.W_100,
                    ),
                    ft.Slider(
                        min=100,
                        max=900,
                        divisions=8,
                        label="Weight = {value}",
                        width=500,
                        on_change=handle_slider_change,
                    ),
                ],
            ),
        ),
    )


if __name__ == "__main__":
    ft.run(main)
python
import flet as ft


def main(page: ft.Page):
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text("Plain text with default style"),
                    ft.Text(
                        "Selectable plain text with default style",
                        selectable=True,
                    ),
                    ft.Text(
                        value="Some text",
                        selectable=True,
                        size=30,
                        spans=[
                            ft.TextSpan(
                                text="here goes italic",
                                style=ft.TextStyle(
                                    italic=True,
                                    size=20,
                                    color=ft.Colors.GREEN,
                                ),
                                spans=[
                                    ft.TextSpan(
                                        text="bold and italic",
                                        style=ft.TextStyle(weight=ft.FontWeight.BOLD),
                                    ),
                                    ft.TextSpan(
                                        text="just italic",
                                        spans=[
                                            ft.TextSpan(
                                                "smaller italic",
                                                ft.TextStyle(size=15),
                                            )
                                        ],
                                    ),
                                ],
                            )
                        ],
                    ),
                    ft.Text(
                        disabled=False,
                        spans=[
                            ft.TextSpan(
                                text="underlined and clickable",
                                style=ft.TextStyle(
                                    decoration=ft.TextDecoration.UNDERLINE
                                ),
                                on_click=lambda e: print(f"Clicked span: {e.control}"),
                                on_enter=lambda e: print(f"Entered span: {e.control}"),
                                on_exit=lambda e: print(f"Exited span: {e.control}"),
                            ),
                            ft.TextSpan(text=" "),
                            ft.TextSpan(
                                text="underlined red wavy",
                                style=ft.TextStyle(
                                    decoration=ft.TextDecoration.UNDERLINE,
                                    decoration_color=ft.Colors.RED,
                                    decoration_style=ft.TextDecorationStyle.WAVY,
                                ),
                                on_enter=lambda e: print(f"Entered span: {e.control}"),
                                on_exit=lambda e: print(f"Exited span: {e.control}"),
                            ),
                            ft.TextSpan(text=" "),
                            ft.TextSpan(
                                text="overlined blue",
                                style=ft.TextStyle(
                                    decoration=ft.TextDecoration.OVERLINE,
                                    decoration_color="blue",
                                ),
                            ),
                            ft.TextSpan(text=" "),
                            ft.TextSpan(
                                text="overlined and underlined",
                                style=ft.TextStyle(
                                    decoration=ft.TextDecoration.OVERLINE
                                    | ft.TextDecoration.UNDERLINE
                                ),
                            ),
                            ft.TextSpan(text=" "),
                            ft.TextSpan(
                                text="line through thick",
                                style=ft.TextStyle(
                                    decoration=ft.TextDecoration.LINE_THROUGH,
                                    decoration_thickness=3,
                                ),
                            ),
                        ],
                    ),
                ],
            ),
        ),
    )

    def handle_link_highlight(e: ft.Event[ft.TextSpan]):
        e.control.style.color = ft.Colors.BLUE
        e.control.update()

    def handle_link_unhighlight(e: ft.Event[ft.TextSpan]):
        e.control.style.color = None
        e.control.update()

    page.add(
        ft.Text(
            disabled=False,
            spans=[
                ft.TextSpan(
                    text="Go to Google",
                    style=ft.TextStyle(decoration=ft.TextDecoration.UNDERLINE),
                    url="https://google.com",
                    on_enter=handle_link_highlight,
                    on_exit=handle_link_unhighlight,
                )
            ],
        ),
    )


if __name__ == "__main__":
    ft.run(main)
python
import flet as ft


def main(page: ft.Page):
    page.add(
        ft.SafeArea(
            content=ft.Stack(
                controls=[
                    ft.Text(
                        spans=[
                            ft.TextSpan(
                                text="Greetings, planet!",
                                style=ft.TextStyle(
                                    size=40,
                                    weight=ft.FontWeight.BOLD,
                                    foreground=ft.Paint(
                                        color=ft.Colors.BLUE_700,
                                        stroke_width=6,
                                        style=ft.PaintingStyle.STROKE,
                                    ),
                                ),
                            ),
                        ],
                    ),
                    ft.Text(
                        spans=[
                            ft.TextSpan(
                                text="Greetings, planet!",
                                style=ft.TextStyle(
                                    size=40,
                                    weight=ft.FontWeight.BOLD,
                                    color=ft.Colors.GREY_300,
                                ),
                            ),
                        ],
                    ),
                ]
            ),
        )
    )


if __name__ == "__main__":
    ft.run(main)
python
import flet as ft


def main(page: ft.Page):
    page.add(
        ft.SafeArea(
            content=ft.Text(
                spans=[
                    ft.TextSpan(
                        text="Greetings, planet!",
                        style=ft.TextStyle(
                            size=40,
                            weight=ft.FontWeight.BOLD,
                            foreground=ft.Paint(
                                gradient=ft.PaintLinearGradient(
                                    begin=(0, 20),
                                    end=(150, 20),
                                    colors=[ft.Colors.RED, ft.Colors.YELLOW],
                                )
                            ),
                        ),
                    ),
                ],
            ),
        )
    )


if __name__ == "__main__":
    ft.run(main)

属性 ​

名称类型默认值说明
valuestr''显示的文本。
spansOptional[list[TextSpan]]None用于构建富文本段落的 TextSpan 对象列表。
text_alignTextAlignTextAlign.START文本的水平对齐方式。
font_familyOptional[str]None用于渲染文本的系统字体或自定义字体族。有关如何在应用中导入和使用自定义字体,请参阅 Fonts 常用食谱指南。
font_family_fallbackOptional[list[str]]None当 font_family 中缺少某个字形时使用的、按顺序排列的备用字体族。
sizeOptional[Number]None以虚拟像素为单位的文本大小。默认值为 14。
weightOptional[FontWeight]None字体粗细。默认值为 FontWeight.NORMAL。
italicboolFalse是否使用斜体字形。
styleOptional[TextStyle]None文本的样式。
theme_styleOptional[TextThemeStyle]None预定义的文本样式。
max_linesOptional[int]None文本可选的最大行数,必要时会换行。如果文本超出给定的行数,将根据 overflow 进行截断。如果该值为 1,文本不会换行;否则文本会在框的边缘处换行。
overflowTextOverflowTextOverflow.CLIP定义文本的溢出方式。
selectableOptional[bool]None文本是否可选中。默认值为 False。
no_wrapboolFalse若为 False(默认),文本会在软换行处断开。若为 True,文本中的字形将按水平空间无限大的方式排列。默认值为 False。
colorOptional[ColorValue]None文本的前景色。
bgcolorOptional[ColorValue]None文本的背景色。
semantics_labelOptional[str]None此文本的备用语义标签。如果设置了该值,此控件的语义信息将包含该值而不是实际文本,并会覆盖所有 TextSpan.semantics_label。这在用完整文本替换缩写或简写时很有用: python ft.Text("$$", semantics_label="Double dollars")
show_selection_cursorboolFalse选中文本时是否显示光标(闪烁的插入符)。注意:仅当 selectable 为 True 时生效。
enable_interactive_selectionboolTrue是否启用用于更改文本选区的用户界面操作。例如,将其设为 True 会启用长按选择文本并显示剪切/复制/粘贴菜单、点击移动文本插入符等功能。反之,若为 False,用户无法调整文本选区,也无法复制文本。注意:仅当 selectable 为 True 时生效。
selection_cursor_widthNumber2.0定义光标的粗细。光标绘制在文本下方。对于从左到右的文本,光标宽度会向字符边界的右侧延伸;对于从右到左的文本则向左侧延伸。这相当于相对于选中位置向下游延伸。可以使用负值来反转此行为。注意:仅当 selectable 为 True 时生效。
selection_cursor_heightOptional[Number]None定义光标的高度。
selection_cursor_colorOptional[ColorValue]None光标的颜色。光标指示当前文本的插入位置。
widthOptional[Number]None控件的强制宽度(以虚拟像素为单位)。
heightOptional[Number]None控件的强制高度(以虚拟像素为单位)。
leftOptional[Number]None子控件左边缘相对于 Stack 左侧的内缩距离。注意:仅当此控件是以下之一的后代时才生效:Stack 控件、overlay 列表。
topOptional[Number]None子控件上边缘相对于 Stack 顶部的内缩距离。注意:仅当此控件是以下之一的后代时才生效:Stack 控件、overlay 列表。
rightOptional[Number]None子控件右边缘相对于 Stack 右侧的内缩距离。注意:仅当此控件是以下之一的后代时才生效:Stack 控件、overlay 列表。
bottomOptional[Number]None子控件下边缘相对于 Stack 底部的内缩距离。注意:仅当此控件是以下之一的后代时才生效:Stack 控件、overlay 列表。
alignOptional[Alignment]None控件在其父级中的对齐方式。
marginOptional[MarginValue]None设置控件的外边距。
rotateOptional[RotateValue]None围绕控件中心旋转来变换此控件。rotate 属性的值可以是以下类型之一: * number —— 顺时针旋转的弧度值。整圈 360° 为 math.pi * 2 弧度,90° 为 pi / 2,45° 为 pi / 4,以此类推。 * Rotate —— 允许同时指定旋转 angle 和 alignment,即旋转中心的位置。 示例: python ft.Image( src="https://picsum.photos/100/100", width=100, height=100, border_radius=5, rotate=Rotate(angle=0.25 * pi, alignment=ft.Alignment.CENTER_LEFT) )
scaleOptional[ScaleValue]None沿二维平面缩放此控件。默认缩放因子为 1.0,表示不缩放。 例如,将此属性设为 0.5 会让控件缩小一半,而设为 2.0 则会放大一倍。 通过将 Control.scale 属性设为 Scale 类的实例,可以为 x 和 y 轴指定不同的缩放倍数。可以指定 scale,或者指定 scale_x 和 scale_y,但不能同时指定全部。 示例: python ft.Image( src="https://picsum.photos/100/100", width=100, height=100, border_radius=5, scale=ft.Scale(scale_x=2, scale_y=0.5) )
offsetOptional[OffsetValue]None在绘制控件之前应用平移变换。 平移量表示为按控件尺寸缩放的 Offset。例如,Offset(x=0.25, y=0) 会使控件沿水平方向平移其宽度的四分之一。 示例 下面的示例把容器显示在 Stack 的 0, 0 左上角,因为变换对控件应用了 -1 * 100, -1 * 100(即 offset * control's size)的水平与垂直平移: python import flet as ft def main(page: ft.Page): page.add( ft.Stack( width=1000, height=1000, controls=[ ft.Container( bgcolor=ft.Colors.RED, width=100, height=100, left=100, top=100, offset=ft.Offset(-1, -1), ) ], ) ) ft.run(main)
flipOptional[Flip]None水平方向和/或垂直方向翻转此控件。设为 Flip 的实例即可沿 x 轴、y 轴或两者镜像翻转。
transformOptional[Transform]None对此控件应用通用矩阵变换。设为带 Matrix4 记录的 Transform 实例,用以描述任意的变换序列。
aspect_ratioOptional[Number]None控件的宽高比,定义为 width 与 height 的比值。注意:在当前实现中,如果设置了 aspect_ratio,同一控件上的 width 和 height 将在最终渲染尺寸中被忽略。
animate_opacityOptional[AnimationValue]None启用 opacity 属性的隐式动画。更多信息见此处。
animate_sizeOptional[AnimationValue]None启用此控件尺寸的隐式动画。如果设置了 width 或 height,则这些维度的变化会以动画呈现。如果两者都未设置,则对控件自然尺寸的变化进行动画。更多信息见此处。
animate_positionOptional[AnimationValue]None启用定位属性(left、right、top 和 bottom)的隐式动画。更多信息见此处。
animate_alignOptional[AnimationValue]None启用 align 属性的隐式动画。更多信息见此处。
animate_marginOptional[AnimationValue]None启用 margin 属性的隐式动画。更多信息见此处。
animate_rotationOptional[AnimationValue]None启用 rotate 属性的隐式动画。更多信息见此处。
animate_scaleOptional[AnimationValue]None启用 scale 属性的隐式动画。更多信息见此处。
animate_offsetOptional[AnimationValue]None启用 offset 属性的隐式动画。更多信息见此处。
size_change_intervalint10on_size_change 事件的采样间隔(毫秒)。设为 0 时,每次变化都会立即调用 on_size_change。
expandAnnotated[Optional[Union[bool, int]], V.instance_of((bool, int))]None指定此控件是否/如何扩展以填满父布局中的可用空间。更多信息见此处。注意:仅当此控件的直接父级是以下控件或其子类时才生效:Column、Row、View、Page。抛出异常:ValueError:如果它不是 bool 或 int 类型。
expand_looseboolFalse允许控件在主轴方向有可用空间时扩展,但不要求它填满所有可用空间。更多信息见此处。注意:如果 expand_loose 为 True,则仅在以下条件满足时才生效: - expand 不为 None,且 - 此控件的直接父级是以下控件或其子类之一:Column、Row、View、Page。
colResponsiveNumber12如果此控件的父级是 ResponsiveRow,则此属性决定该控件在屏幕上跨越多少虚拟列。可以是一个数字,也可以是一个按断点配置不同值的字典,例如 col={"sm": 6}。值为 0 时会在该断点隐藏控件,因此它不会占用父级 ResponsiveRow 中的任何列。此控件默认跨越 12 个虚拟列。 | 断点 | 尺寸 | |---|---| | xs | <576px | | sm | ≥576px | | md | ≥768px | | lg | ≥992px | | xl | ≥1200px | | xxl | ≥1400px |
opacityAnnotated[Number, V.between(0.0, 1.0)]1.0定义控件的透明度。取值范围从 0.0(完全透明)到 1.0(完全不透明,无任何透明感)。抛出异常:ValueError:如果它不在 0.0 到 1.0(含)之间。
tooltipOptional[TooltipValue]None鼠标悬停在此控件上时显示的工具提示。
badgeOptional[BadgeValue]None显示在此控件顶部的徽章。
visibleboolTrue每个控件都有 visible 属性,默认为 True —— 控件会渲染在页面上。将 visible 设为 False 会彻底阻止控件(及其所有子控件,如果有)渲染到页面画布上。隐藏的控件无法通过键盘或鼠标获得焦点或选中,也不会触发任何事件。
disabledboolFalse每个控件都有 disabled 属性,默认为 False —— 控件及其所有子控件都处于启用状态。注意:此属性的值会递归向下传播到所有子控件。示例:例如,如果你有一个包含多个输入控件的表单,可以通过禁用容器来一并禁用它们: python ft.Column( disabled = True, controls=[ ft.TextField(), ft.TextField() ] )
rtlboolFalse控件的文本方向是否为从右到左(RTL)。
dataAnyskip_任意类型的自定义数据。
keyOptional['KeyValue']None用于在更新之间保持控件标识稳定的键。

只读属性 ​

名称类型默认值说明
parentOptional['BaseControl']—此控件的直接祖先(父级)。默认为 None,只有在此控件被挂载(加入页面树)后才有值。Page 控件(页面树的根)是个例外 —— 它的 parent 始终为 None。
page'Page'—此控件所属的页面。

事件 ​

名称类型默认值说明
on_tapOptional[ControlEventHandler['Text']]None当用户点按此可选文本时调用。注意:仅当 selectable 为 True 时生效。
on_selection_changeOptional[EventHandler[TextSelectionChangeEvent['Text']]]None当用户更改文本选区(包括光标位置)时调用。注意:仅当 selectable 为 True 时生效。
on_size_changeOptional[EventHandler[LayoutSizeChangeEvent['LayoutControl']]]None当此控件的尺寸发生变化时调用。size_change_interval 定义此事件的调用频率。
on_animation_endOptional[ControlEventHandler['LayoutControl']]None动画完成时调用。可用于串联多个动画。事件处理器参数的 data 属性包含动画名称。更多信息见此处。

方法 ​

名称类型默认值说明
is_isolated——返回此控件是否被标记为隔离。隔离控件会被排除在父级驱动的更新遍历之外,并需要自行管理更新边界。
init——在控件实例初始化之后、首次 build/update 周期之前调用。重写此钩子以执行依赖已初始化字段的轻量级设置。不要在此处调用 update()。
build——在控件初始化期间调用一次,用于定义其子控件。在此方法中 page 属性可用。
before_update——每当此控件被更新时都会调用此方法。注意:务必不要在此处调用或请求 update()。
before_event——在事件处理器执行之前拦截事件。返回 False 可取消分发。返回 True 或 None 则继续正常的事件处理。
did_mount——在控件挂载到页面树之后调用。重写此方法以启动需要已挂载页面的资源,例如订阅、定时器或服务监听器。
will_unmount——在控件从页面树移除之前调用。重写此方法以释放 did_mount() 中创建的资源,例如订阅、定时器或外部句柄。
get_data_channel——解析为此 widget 在 Dart 侧分配的 [DataChannel]。模式: on_data_channel_open: Optional[ft.EventHandler[DataChannelOpenEvent]] = None def init(self): self.on_data_channel_open = self._on_open def _on_open(self, e): self._channel = self.get_data_channel(e.channel_id) 幂等 —— 底层的 Connection 会按 id 缓存 DataChannel,因此重复调用会返回同一实例。没有错误路径:该 id 始终来自框架触发的事件,所以当此方法运行时,通道在两端都已存在。
updateNone—为此控件请求一次 UI 更新。在更改控件状态或属性后调用。控件必须已挂载到页面且未被标记为冻结。

关注我,学习大模型、大数据、Python等热门技术。