Skip to content

Context

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

Context instance is accessed via flet.context.

Properties

  • page(Page) –

    Returns the current Page associated with the context.

Methods

Properties#

page property #

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() -> bool

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

```python 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() -> bool

Returns whether the current context is in components mode.

Returns:

  • bool

    True if in components mode, False otherwise.

reset_auto_update #

reset_auto_update()

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