Skip to main content

Context

Manages the context for Flet controls, including page reference and auto-update behavior.

Context instance is accessed via flet.context.

Properties

  • page - Returns the current Page associated with the context.

Methods

Properties

pageproperty

page: Page

Returns the current Page associated with the context.

Example
# take page width anywhere in the app
width = ft.context.page.width

Returns:

  • Page - The current page.

Raises:

  • RuntimeError - If the property is accessed outside a running Flet app.

Methods

auto_update_enabled

auto_update_enabled()

Returns whether auto-update is enabled in the current context.

Returns:

  • bool - True if auto-update is enabled, False otherwise.

disable_auto_update

disable_auto_update()

Disables auto-update behavior for the current context.

Example
import flet as ft


def main(page: ft.Page):
def button_click():
ft.context.disable_auto_update()
b.content = "Button clicked!"
# update just the button
b.update()

page.controls.append(ft.Text("This won't appear"))
# no page.update() will be called here

page.controls.append(b := ft.Button("Action!", on_click=button_click))
# page.update() - auto-update is enabled by default


ft.run(main)

enable_auto_update

enable_auto_update()

Enables auto-update behavior for the current context.

Example
import flet as ft

# disable auto-update globally for the app
ft.context.disable_auto_update()


def main(page: ft.Page):
# enable auto-update just inside main
ft.context.enable_auto_update()

page.controls.append(ft.Text("Hello, world!"))
# page.update() - we don't need to call it explicitly


ft.run(main)

enable_components_mode

enable_components_mode()

Enables components mode in the current context.

is_components_mode

is_components_mode()

Returns whether the current context is in components mode.

Returns:

  • bool - True if in components mode, False otherwise.

mark_update_called

mark_update_called()

Marks that .update() was explicitly called during the current handler.

reset_auto_update

reset_auto_update()

Copies the parent auto-update state into the current context.

reset_update_called

reset_update_called()

Resets the update-called flag for the current context.

was_update_called

was_update_called()

Returns whether .update() was explicitly called during the current handler.

Returns:

  • bool - True if .update() was called, False otherwise.