Skip to content

Page

Page #

Bases: PageView

Page is a container for View controls.

A page instance and the root view are automatically created when a new user session started.

adaptive #

adaptive: bool | None = None

Enables platform-specific rendering or inheritance of adaptiveness from parent controls.

appbar #

appbar: AppBar | CupertinoAppBar | None

auth #

auth: Authorization | None

auto_scroll #

auto_scroll: bool

badge #

badge: BadgeValue | None = None

A badge to show on top of this control.

bgcolor #

bgcolor: ColorValue | None

bottom_appbar #

bottom_appbar: BottomAppBar | None

browser_context_menu #

browser_context_menu: BrowserContextMenu = field(
    default_factory=lambda: BrowserContextMenu(),
    metadata={"skip": True},
)

Used to enable or disable the context menu that appears when the user right-clicks on the web page.

Note

Web only.

client_ip #

client_ip: str | None = None

IP address of the connected user.

🌎 Web only.

client_user_agent #

client_user_agent: str | None = None

Browser details of the connected user.

🌎 Web only.

clipboard #

clipboard: Clipboard = field(
    default_factory=lambda: Clipboard(),
    metadata={"skip": True},
)

TBD

col #

col: ResponsiveNumber = 12

If a parent of this control is a ResponsiveRow, 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

controls #

controls: list[BaseControl]

dark_theme #

dark_theme: Theme | None = None

Customizes the theme of the application when in dark theme mode.

data #

data: Any = skip_field()

Arbitrary data of any type.

debug #

debug: bool = False

True if Flutter client of Flet app is running in debug mode.

decoration #

decoration: BoxDecoration | None

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.

Example

For example, if you have a form with multiple entry controls you can disable them all together by disabling container:

ft.Column(
    disabled = True,
    controls=[
        ft.TextField(),
        ft.TextField()
    ]
)

drawer #

drawer: NavigationDrawer | None

end_drawer #

end_drawer: NavigationDrawer | None

executor #

executor: ThreadPoolExecutor | None

expand #

expand: bool | int | None = None

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, Row, View, Page.

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 not None and
  • the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page.

floating_action_button #

floating_action_button: FloatingActionButton | None

floating_action_button_location #

floating_action_button_location: (
    FloatingActionButtonLocation | OffsetValue | None
)

fonts #

fonts: dict[str, str] | None = None

Defines the custom fonts to be used in the application.

Value is a dictionary, in which the keys represent the font family name used for reference and the values: - Key: The font family name used for reference. - Value: The font source, either an absolute URL or a relative path to a local asset. The following font file formats are supported .ttc, .ttf and .otf.

Usage example here.

foreground_decoration #

foreground_decoration: BoxDecoration | None

height #

height: Number | None = None

horizontal_alignment #

horizontal_alignment: CrossAxisAlignment | None

key #

key: (
    str | int | float | bool | ValueKey | ScrollKey | None
) = None

locale_configuration #

locale_configuration: LocaleConfiguration | None = None

loop #

media #

media: PageMediaData | None = None

multi_view #

multi_view: bool = False

TBD

multi_views #

multi_views: list[MultiView] = field(default_factory=list)

TBD

name #

name: str

navigation_bar #

navigation_bar: (
    NavigationBar | CupertinoNavigationBar | None
)

on_app_lifecycle_state_change #

on_app_lifecycle_state_change: (
    EventHandler[AppLifecycleStateChangeEvent] | None
) = None

Triggers when app lifecycle state changes.

on_close #

on_close: ControlEventHandler[Page] | None = None

Called when a session has expired after configured amount of time (60 minutes by default).

on_connect #

on_connect: ControlEventHandler[Page] | None = None

Called when a web user (re-)connects to a page session.

It is not triggered when an app page is first opened, but is triggered when the page is refreshed, or Flet web client has re-connected after computer was unlocked. This event could be used to detect when a web user becomes "online".

on_disconnect #

on_disconnect: ControlEventHandler[Page] | None = None

Called when a web user disconnects from a page session, i.e. closes browser tab/window.

on_error #

on_error: ControlEventHandler[Page] | None = None

Called when unhandled exception occurs.

on_keyboard_event #

on_keyboard_event: EventHandler[KeyboardEvent] | None = None

Called when a keyboard key is pressed.

on_login #

on_login: EventHandler[LoginEvent] | None = None

Called upon successful or failed OAuth authorization flow.

See Authentication guide for more information and examples.

on_logout #

on_logout: ControlEventHandler[Page] | None = None

Called after page.logout() call.

on_media_change #

on_media_change: ControlEventHandler[PageView] | None = None

Called when page.media has changed.

Event type: PageMediaData

on_multi_view_add #

on_multi_view_add: (
    EventHandler[MultiViewAddEvent] | None
) = None

TBD

on_multi_view_remove #

on_multi_view_remove: (
    EventHandler[MultiViewRemoveEvent] | None
) = None

TBD

on_platform_brightness_change #

on_platform_brightness_change: (
    ControlEventHandler[Page] | None
) = None

Called when brightness of app host platform has changed.

on_resize #

on_resize: EventHandler[PageResizeEvent] | None = None

Called when a user resizes a browser or native OS window containing Flet app, for example:

def page_resize(e):
    print("New page size:", page.window.width, page.window_height)

page.on_resize = page_resize

on_route_change #

on_route_change: EventHandler[RouteChangeEvent] | None = (
    None
)

Called when page route changes either programmatically, by editing application URL or using browser Back/Forward buttons.

on_scroll #

on_scroll: EventHandler[OnScrollEvent] | None = None

Called when page's scroll position is changed by a user.

on_view_pop #

on_view_pop: EventHandler[ViewPopEvent] | None = None

Called when the user clicks automatic "Back" button in AppBar control.

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).

overlay #

overlay: list[BaseControl]

padding #

padding: PaddingValue | None

page #

page: Page | PageView | None

The page (of type Page or PageView) to which this control belongs to.

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.

platform #

platform: PagePlatform | None = None

Operating system the application is running on.

platform_brightness #

platform_brightness: Brightness | None = None

The current brightness mode of the host platform. (readonly)

pubsub #

pubsub: PubSubClient

pwa #

pwa: bool = False

True if the application is running as Progressive Web App (PWA).

Value is read-only.

query #

query: QueryString

route #

route: str | None = None

Get or sets page's navigation route. See Navigation and routing section for more information and examples.

rtl #

rtl: bool = False

Whether the text direction of the control should be right-to-left (RTL).

scroll #

scroll: ScrollMode | None

scroll_event_interval #

scroll_event_interval: Number | None = None

services #

services: list[Service]

session #

session: SessionStorage

shared_preferences #

shared_preferences: SharedPreferences = field(
    default_factory=lambda: SharedPreferences(),
    metadata={"skip": True},
)

TBD

show_semantics_debugger #

show_semantics_debugger: bool | None = None

True turns on an overlay that shows the accessibility information reported by the framework.

spacing #

spacing: Number | None

storage_paths #

storage_paths: StoragePaths = field(
    default_factory=lambda: StoragePaths(),
    metadata={"skip": True},
)

TBD

theme #

theme: Theme | None = 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.

theme_mode #

theme_mode: ThemeMode | None = SYSTEM

The page's theme mode.

Defaults to ThemeMode.SYSTEM.

title #

title: str | None = None

tooltip #

tooltip: TooltipValue | None = None

The tooltip ot show when this control is hovered over.

url #

url: str | None

url_launcher #

url_launcher: UrlLauncher = field(
    default_factory=lambda: UrlLauncher(),
    metadata={"skip": True},
)

TBD

vertical_alignment #

vertical_alignment: MainAxisAlignment | None

views #

views: list[View] = field(default_factory=lambda: [View()])

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.

wasm #

wasm: bool = False

TBD

web #

web: bool = False

True if the application is running in the web browser.

width #

width: Number | None = None

window #

window: Window = field(default_factory=lambda: Window())

A class with properties/methods/events to control app's native OS window.

add #

add(*controls: Control) -> None

Adds controls to the page.

page.add(ft.Text("Hello!"), ft.FilledButton("Button"))

before_event #

before_event(e: ControlEvent)

before_update #

before_update()

can_launch_url_async #

can_launch_url_async(url: str)

Checks whether the specified URL can be handled by some app installed on the device.

Returns True if it is possible to verify that there is a handler available. A False return value can indicate either that there is no handler available, or that the application does not have permission to check. For example:

  • On recent versions of Android and iOS, this will always return False unless the application has been configuration to allow querying the system for launch support.
  • On web, this will always return False except for a few specific schemes that are always assumed to be supported (such as http(s)), as web pages are never allowed to query installed applications.

clean #

clean() -> None

close #

close(control: DialogControl) -> None

close_in_app_web_view #

close_in_app_web_view() -> None

Closes in-app web view opened with launch_url().

📱 Mobile only.

close_in_app_web_view_async #

close_in_app_web_view_async() -> None

Closes in-app web view opened with launch_url().

📱 Mobile only.

did_mount #

did_mount()

error #

error(message: str) -> None

get_control #

get_control(id: int) -> BaseControl | None

Get a control by its id.

Example:

import flet as ft

def main(page: ft.Page):
    x = ft.IconButton(ft.Icons.ADD)
    page.add(x)
    print(type(page.get_control(x.uid)))

ft.run(main)

get_session #

get_session()

get_upload_url #

get_upload_url(file_name: str, expires: int) -> str

Generates presigned upload URL for built-in upload storage:

  • file_name - a relative to upload storage path.
  • expires - a URL time-to-live in seconds.

For example:

upload_url = page.get_upload_url("dir/filename.ext", 60)

To enable built-in upload storage provide upload_dir argument to flet.app() call:

ft.run(main, upload_dir="uploads")

go #

go(
    route: str,
    skip_route_change_event: bool = False,
    **kwargs: Any,
) -> None

A helper method that updates page.route, calls page.on_route_change event handler to update views and finally calls page.update().

init #

init()

insert #

insert(at: int, *controls: Control) -> None

Inserts controls at specific index of page.controls list.

is_isolated #

is_isolated()

launch_url #

launch_url(
    url: str,
    web_window_name: str | None = None,
    web_popup_window: bool | None = False,
    window_width: int | None = None,
    window_height: int | None = None,
) -> None

Opens url in a new browser window.

Optional method arguments:

  • web_window_name - window tab/name to open URL in: UrlTarget.SELF - the same browser tab, UrlTarget.BLANK - a new browser tab (or in external application on mobile device) or <your name> - a named tab.
  • web_popup_window - set to True to display a URL in a browser popup window. Defaults to False.
  • window_width - optional, popup window width.
  • window_height - optional, popup window height.

launch_url_async #

launch_url_async(
    url: str,
    web_window_name: str | None = None,
    web_popup_window: bool | None = False,
    window_width: int | None = None,
    window_height: int | None = None,
) -> None

Opens provided url in a new browser window.

PARAMETER DESCRIPTION
url

The URL to open.

TYPE: str

web_window_name

Window tab/name to open URL in. Use UrlTarget.SELF for the same browser tab, UrlTarget.BLANK for a new browser tab (or in external application on mobile device), or a custom name for a named tab.

TYPE: str | None DEFAULT: None

web_popup_window

Display the URL in a browser popup window.

TYPE: bool | None DEFAULT: False

window_width

Popup window width.

TYPE: int | None DEFAULT: None

window_height

Popup window height.

TYPE: int | None DEFAULT: None

login_async #

login_async(
    provider: OAuthProvider,
    fetch_user: bool = True,
    fetch_groups: bool = False,
    scope: list[str] | None = None,
    saved_token: str | None = None,
    on_open_authorization_url: Callable[
        [str], Coroutine[Any, Any, None]
    ]
    | None = None,
    complete_page_html: str | None = None,
    redirect_to_page: bool | None = False,
    authorization: type[AT] = AuthorizationImpl,
) -> AT

Starts OAuth flow.

See Authentication guide for more information and examples.

logout #

logout() -> None

Clears current authentication context. See Authentication guide for more information and examples.

open #

open(control: DialogControl) -> None

pop_dialog #

pop_dialog() -> DialogControl | None

remove #

remove(*controls: Control) -> None

Removes specific controls from page.controls list.

remove_at #

remove_at(index: int) -> None

Remove controls from page.controls list at specific index.

run_task #

run_task(
    handler: Callable[InputT, Awaitable[RetT]],
    *args: args,
    **kwargs: kwargs,
) -> Future[RetT]

Run handler coroutine as a new Task in the event loop associated with the current page.

run_thread #

run_thread(
    handler: Callable[InputT, Any],
    *args: args,
    **kwargs: kwargs,
) -> None

Run handler function as a new Thread in the executor associated with the current page.

scroll_to #

scroll_to(
    offset: Number | None = None,
    delta: Number | None = None,
    scroll_key: str
    | int
    | float
    | bool
    | ScrollKey
    | None = None,
    duration: DurationValue | None = None,
    curve: AnimationCurve | None = None,
) -> None

Moves scroll position to either absolute offset, relative delta or jump to the control with specified scroll_key.

See Column.scroll_to() for method details and examples.

show_dialog #

show_dialog(dialog: DialogControl) -> None

TBD

update #

update(*controls) -> None

will_unmount #

will_unmount()