Context
Manages the context for Flet controls, including page reference and auto-update behavior.
Context instance is accessed via flet.context.
Properties
Methods
auto_update_enabled- Returns whether auto-update is enabled in the current context.disable_auto_update- Disables auto-update behavior for the current context.enable_auto_update- Enables auto-update behavior for the current context.enable_components_mode- Enables components mode in the current context.is_components_mode- Returns whether the current context is in components mode.mark_update_called- Marks that.update()was explicitly called during the current handler.reset_auto_update- Copies the parent auto-update state into the current context.reset_update_called- Resets the update-called flag for the current context.was_update_called- Returns whether.update()was explicitly called during the current handler.
Properties
Methods
auto_update_enabled
auto_update_enabled()Returns whether auto-update is enabled in the current context.
Returns:
- bool -
Trueif auto-update is enabled,Falseotherwise.
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)
is_components_mode
is_components_mode()Returns whether the current context is in components mode.
Returns:
- bool -
Trueif in components mode,Falseotherwise.
mark_update_called
mark_update_called()Marks that .update() was explicitly called during the current handler.
was_update_called
was_update_called()Returns whether .update() was explicitly called during the current handler.
Returns:
- bool -
Trueif.update()was called,Falseotherwise.