主题
MultiView 继承自: BasePage, AdaptiveControl, Control, BaseControl
表示由多视图会话(multi-view session)管理的附加应用视图。
多视图会话可以为同一个应用创建多个视图。每个视图都有各自的 view_id,并可以通过 initial_data 接收一个初始载荷。
属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
view_id | int | required | Unique identifier of this view. |
initial_data | dict[str, Any] | required | Initial payload provided when this view was opened. |
views | list[View] | [View()]() | A list of views managed by the page. Each View represents a distinct navigation state or screen in the application. The first view in the list is considered the active one by default. |
theme_mode | Optional[ThemeMode] | ThemeMode.SYSTEM | The page's theme mode. |
theme | Optional['Theme'] | None | Customizes the theme of the application when in light theme mode. Currently, a theme can only be automatically generated from a "seed" color. For example, to generate light theme from a green color. |
dark_theme | Optional['Theme'] | None | Customizes the theme of the application when in dark theme mode. |
theme_animation_style | Optional[AnimationStyle] | None | Overrides the default animation style used when the application's theme is changed (for example, when theme_mode switches between light and dark). Tip: Use no_animation to disable the theme transition entirely. |
locale_configuration | Optional[LocaleConfiguration] | None | Configures supported locales and the current locale. |
show_semantics_debugger | bool | False | Whether to turn on an overlay that shows the accessibility information reported by the framework. |
title | Optional[str] | None | Page or window title. |
enable_screenshots | bool | False | Enable taking screenshots of the entire page with take_screenshot method. |
media | PageMediaData | PageMediaData(padding=Padding.zero()() | The current environmental metrics of the page or window. This data is updated whenever the platform window or layout changes, such as when rotating a device, resizing a browser window, or adjusting system UI elements like the keyboard or safe areas. |
width | Optional[Number] | None | Page width in logical pixels. Note: - This property is read-only. - To get or set the full window height including window chrome (e.g., title bar and borders) when running a Flet app on desktop, use the width property of window instead. |
height | Optional[Number] | None | Page height in logical pixels. Note: - This property is read-only. - To get or set the full window height including window chrome (e.g., title bar and borders) when running a Flet app on desktop, use the height property of window instead. |
adaptive | Optional[bool] | None | Enables platform-specific rendering or inheritance of adaptiveness from parent controls. |
expand | Annotated[Optional[Union[bool, int]], V.instance_of((bool, int))] | None | 指定此控件是否/如何扩展以填充父布局中的可用空间。 详见 此处. Note: Has effect only if the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page. Raises: ValueError: If it is not of type bool or int. |
expand_loose | bool | False | 允许控件在主轴方向上有可用空间时扩展,但不要求填满所有可用空间。 详见 此处. Note: 若 expand_loose 为 True,则仅当同时满足以下条件时生效: - expand 不为 None,且 - the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page. |
col | ResponsiveNumber | 12 | 若此控件的父控件是 ResponsiveRow,此属性用于决定该控件横跨多少个虚拟列。 可以是数字,也可以是为不同断点配置不同值的字典,例如 col={"sm": 6}。 0 表示在该断点下隐藏控件,不占用任何列。 默认横跨 12 个虚拟列。 \ |
opacity | Annotated[Number, V.between(0.0, 1.0)] | 1.0 | 定义控件的透明度,取值范围 0.0(完全透明)到 1.0(完全不透明)。 抛出异常:ValueError:若不在 0.0 到 1.0 的闭区间内。 |
tooltip | Optional[TooltipValue] | None | 鼠标悬停时显示的 tooltip。 |
badge | Optional[BadgeValue] | None | 显示在控件顶部的徽标。 |
visible | bool | True | Every control has visible property which is True by default - control is rendered on the page. Setting visible to False 完全阻止该控件(及其所有子控件)渲染到页面画布上. 隐藏的控件不能通过键盘或鼠标聚焦或选中,也不会触发任何事件。 |
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. Example: For example, if you have a form with multiple entry controls you can disable them all together by disabling container: python ft.Column( disabled = True, controls=[ ft.TextField(), ft.TextField() ] ) |
rtl | bool | False | 控件的文字方向是否为从右到左(RTL)。 |
data | Any | skip_ | 任意类型的自定义数据。 |
key | Optional['KeyValue'] | None | 用于在更新之间保持控件身份稳定的 key。 |
只读属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
overlay | list[BaseControl] | — | The list of overlay controls rendered above page content. |
controls | list[BaseControl] | — | Root view content controls displayed by this page. |
appbar | 'Union[AppBar, CupertinoAppBar, None]' | — | Gets or sets the top application bar (AppBar or CupertinoAppBar) for the view. The app bar typically displays the page title and optional actions such as navigation icons, menus, or other interactive elements. |
bottom_appbar | Optional[BottomAppBar] | — | Bottom app bar displayed in the root view. |
navigation_bar | 'Optional[Union[NavigationBar, CupertinoNavigationBar]]' | — | Bottom navigation bar for the root view. |
drawer | Optional[NavigationDrawer] | — | Navigation drawer opened from the leading edge. |
end_drawer | Optional[NavigationDrawer] | — | Navigation drawer opened from the trailing edge. |
decoration | Optional[BoxDecoration] | — | Background decoration of the root view container. |
foreground_decoration | Optional[BoxDecoration] | — | Foreground decoration painted above root view content. |
floating_action_button | Optional[FloatingActionButton] | — | Floating action button shown for the root view. |
floating_action_button_location | Optional[Union[FloatingActionButtonLocation, OffsetValue]] | — | Placement of the floating action button in the root view. |
horizontal_alignment | CrossAxisAlignment | — | Horizontal alignment of root view child controls. |
vertical_alignment | MainAxisAlignment | — | Vertical alignment of root view child controls. |
spacing | Number | — | Default spacing between root view child controls. |
padding | Optional[PaddingValue] | — | Inner padding for the root view content. |
bgcolor | Optional[ColorValue] | — | Background color of the root view. |
scroll | Optional[Union[ScrollMode, Scrollbar]] | — | Scroll behavior mode for root view content. |
auto_scroll | bool | — | Whether root view should auto-scroll to the end on content changes. |
services | list[Service] | — | Service instances attached to the root view lifecycle. |
parent | Optional['BaseControl'] | — | 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). Page 控件(树的根)为例外 —— 它始终 parent=None。 |
page | 'Page' | — | 此控件所属的页面。 |
事件
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
on_resize | Optional[EventHandler['PageResizeEvent']] | None | Called when a user resizes a browser or native OS window containing Flet app Example: python def main(page: ft.Page): def handle_page_size(e): print("New page size:", page.window.width, page.window_height) page.on_resize = handle_page_size |
on_media_change | Optional[EventHandler[PageMediaData]] | None | Called when media has changed. |
方法
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
update | None | — | Push pending updates to the connected client. Args: *controls: Specific controls to update. When omitted, updates this page object. |
add | None | — | Adds controls to the page. Example: python page.add(ft.Text("Hello!"), ft.FilledButton("Button")) |
insert | None | — | Inserts controls at specific index of page.controls list. |
remove | None | — | Removes specific controls from page.controls list. |
remove_at | None | — | Remove controls from page.controls list at specific index. |
clean | None | — | Remove all root view controls and send update to the client. |
scroll_to | None | — | Moves scroll position to either absolute offset, relative delta or jump to the control with specified scroll_key. See scroll_to for method details and examples. |
show_dialog | None | — | Displays a dialog and manages its dismissal lifecycle. This method adds the specified dialog to the active dialog stack and renders it on the page. The on_dismiss handler of the dialog is temporarily wrapped to ensure the dialog is removed from the stack and its dismissal event is triggered appropriately. Args: dialog: The dialog instance to display. Must not yet be open. Raises: RuntimeError: If the specified dialog is already open. |
pop_dialog | Optional[DialogControl] | — | Closes the most recently opened dialog. This method searches the active dialog stack for the topmost dialog that is currently open, marks it as closed, updates its state, and returns the closed dialog. Returns: The closed dialog instance if one was found, otherwise None. |
show_drawer | — | — | Show the drawer. Raises: ValueError: If no drawer is defined. |
close_drawer | — | — | Close the drawer. |
show_end_drawer | — | — | Show the end drawer. Raises: ValueError: If no end_drawer is defined. |
close_end_drawer | — | — | Close the end drawer. |
take_screenshot | bytes | — | Captures a screenshot of the entire page with overlays. Args: pixel_ratio: A pixel ratio of the captured screenshot. If None, device-specific pixel ratio will be used. delay: A delay before taking a screenshot. The delay will be 20 milliseconds if not specified. Returns: Screenshot in PNG format. |
take_animation | list[bytes] | — | Captures an animated sequence of page screenshots in a single round-trip. Each entry in frame_delays_ms is the delay in milliseconds to wait before capturing that frame. The wait and capture loop runs entirely on the Flutter side, so animation timing isn't distorted by Python-Flutter RPC latency the way it is with a Python-driven take_screenshot loop. Requires enable_screenshots = True. Args: name: Name prefix for the captured frames (for debugging). frame_delays_ms: Per-frame delays in milliseconds. The list length determines the number of frames captured. pixel_ratio: A pixel ratio of the captured frames. If None, device-specific pixel ratio will be used. Returns: List of PNG-encoded frames, one per entry in frame_delays_ms. |
is_isolated | — | — | Return whether this control is marked as isolated. 被隔离的控件不会参与父级驱动的更新遍历,需要自行管理更新边界。 |
init | — | — | Called after control instance initialization and before the first build / update cycle. 可重写此钩子执行依赖于已初始化字段的轻量设置。 不要在这里调用 update()。 |
build | — | — | 在控件初始化期间调用一次,用于定义其子控件。 page 属性在此方法中可用。 |
before_update | — | — | 每次控件即将更新时调用。 Note: 不要在此处调用 update()。 |
before_event | — | — | 在事件处理器执行前拦截事件。 返回 False 取消分发,返回 True 或 None 则继续正常的事件处理。 |
did_mount | — | — | 在控件挂载到页面树之后调用。 可重写以启动需要已挂载页面的资源,例如订阅、定时器或服务监听。 |
will_unmount | — | — | 在控件从页面树移除之前调用。 可重写以释放 did_mount() 中创建的资源,例如订阅、定时器或外部句柄。 |
get_data_channel | — | — | Resolve the [DataChannel] allocated on the Dart side for this widget. Pattern: 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) Idempotent — the underlying Connection caches DataChannels by id, so repeated calls return the same instance. No error path: the id always comes from a framework-fired event, so by the time this runs the channel exists on both sides. |