Page
Page
#
Bases: BasePage
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
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.
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.
Note
This property is web only.
client_user_agent
#
client_user_agent: str | None = None
Browser details of the connected user.
Note
This property is web only.
clipboard
#
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 |
dark_theme
#
dark_theme: Theme | None = None
Customizes the theme of the application when in dark theme mode.
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_screenshots
#
enable_screenshots: bool = False
Enable taking screenshots of the entire page with take_screenshot
method.
expand
#
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.
floating_action_button_location
#
floating_action_button_location: (
FloatingActionButtonLocation | OffsetValue | None
)
fonts
#
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.
height
#
height: Number | None = 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 ofPage.window
instead.
locale_configuration
#
locale_configuration: LocaleConfiguration | None = None
Configures supported locales and the current locale.
media
#
media: PageMediaData = field(
default_factory=lambda: PageMediaData(
padding=zero(),
view_padding=zero(),
view_insets=zero(),
device_pixel_ratio=0,
)
)
Represents the environmental metrics of a page or window.
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_media_change
#
on_media_change: EventHandler[PageMediaData] | None = None
Called when media
has changed.
on_multi_view_remove
#
on_multi_view_remove: (
EventHandler[MultiViewRemoveEvent] | None
) = None
TBD
on_platform_brightness_change
#
on_platform_brightness_change: (
EventHandler[PlatformBrightnessChangeEvent] | None
) = None
Called when brightness of app host platform has changed.
on_resize
#
on_resize: EventHandler[PageResizeEvent] | None = None
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_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).
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_brightness
#
platform_brightness: Brightness | None = None
The current brightness mode of the host platform.
Note
This property is read-only.
pwa
#
pwa: bool = False
True
if the application is running as Progressive Web App (PWA).
Value is read-only.
route
#
route: str | None = None
Get or sets page's navigation route. See Navigation and routing section for more information and examples.
shared_preferences
#
shared_preferences: SharedPreferences = field(
default_factory=lambda: SharedPreferences(),
metadata={"skip": True},
)
TBD
show_semantics_debugger
#
show_semantics_debugger: bool | None = None
Whether to turn on an overlay that shows the accessibility information reported by the framework.
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.
tooltip
#
tooltip: TooltipValue | None = None
The tooltip ot show when this control is hovered over.
url_launcher
#
url_launcher: UrlLauncher = field(
default_factory=lambda: UrlLauncher(),
metadata={"skip": True},
)
TBD
views
#
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.
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.
width
#
width: Number | None = 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 ofPage.window
instead.
window
#
A class with properties/methods/events to control app's native OS window.
build
#
Called once during control initialization to define its child controls. self.page is available in this method.
can_launch_url
#
Checks whether the specified URL can be handled by some app installed on the device.
PARAMETER | DESCRIPTION |
---|---|
url
|
The URL to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
|
bool
|
|
bool
|
or the application does not have permission to check. For example: |
bool
|
|
bool
|
|
close_in_app_web_view
#
Closes in-app web view opened with launch_url()
.
📱 Mobile only.
get_control
#
get_control(id: int) -> BaseControl | None
get_upload_url
#
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:
To enable built-in upload storage provide upload_dir
argument to flet.app()
call:
go
#
A helper method that updates page.route
, calls
page.on_route_change
event handler to update views and
finally calls page.update()
.
insert
#
Inserts controls at specific index of page.controls
list.
launch_url
#
launch_url(
url: str | Url,
*,
web_popup_window_name: str | UrlTarget | None = None,
web_popup_window: bool = False,
web_popup_window_width: int | None = None,
web_popup_window_height: int | None = None,
) -> None
Opens a web browser or popup window to a given url
.
PARAMETER | DESCRIPTION |
---|---|
url
|
The URL to open. |
web_popup_window_name
|
Window tab/name to open URL in. Use
|
web_popup_window
|
Display the URL in a browser popup window.
TYPE:
|
window_width
|
Popup window width.
|
window_height
|
Popup window height.
|
login
#
login(
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
#
Clears current authentication context. See Authentication guide for more information and examples.
pop_dialog
#
pop_dialog() -> DialogControl | None
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 | DESCRIPTION |
---|---|
DialogControl | None
|
The closed dialog instance if one was found, otherwise |
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 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
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. If the dialog is already open, an exception
is raised.
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.
PARAMETER | DESCRIPTION |
---|---|
dialog
|
The dialog instance to display. Must not already be open.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
Exception
|
If the specified dialog is already open. |
take_screenshot
#
take_screenshot(
pixel_ratio: Number | None = None,
delay: DurationValue | None = None,
) -> bytes
Captures a screenshot of the entire page with overlays.
PARAMETER | DESCRIPTION |
---|---|
pixel_ratio
|
A pixel ratio of the captured screenshot.
If
TYPE:
|
delay
|
A delay before taking a screenshot. The delay will be 20 milliseconds if not specified.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
Screenshot in PNG format. |