Skip to main content

BaseControl

Base class for all Flet controls and services.

Properties

  • data - Arbitrary data of any type.
  • key
  • page - The page to which this control belongs to.
  • parent - The direct ancestor(parent) of this control.

Methods

  • before_event - Intercept an event before its handler is executed.
  • build - Called once during control initialization to define its child controls.
  • did_mount - Called after the control is mounted into the page tree.
  • is_isolated - Return whether this control is marked as isolated.
  • update - Request a UI update for this control.
  • will_unmount - Called before the control is removed from the page tree.

Properties

dataclass-attributeinstance-attribute

data: Any = skip_field()

Arbitrary data of any type.

keyclass-attributeinstance-attribute

key: Optional[KeyValue] = None

pageproperty

page: Union[Page, BasePage]

The page to which this control belongs to.

parentproperty

parent: Optional[BaseControl]

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.

Methods

before_event

before_event(e: ControlEvent)

Intercept an event before its handler is executed.

Return False to cancel dispatch. Return True or None to continue normal event processing.

build

build()

Called once during control initialization to define its child controls. page property is available/usable in this method.

did_mount

did_mount()

Called after the control is mounted into the page tree.

Override to start resources that require an attached page, for example subscriptions, timers, or service listeners.

is_isolated

is_isolated()

Return whether this control is marked as isolated.

Isolated controls are excluded from parent-driven update traversal and are expected to manage their own update boundaries.

update

update()

Request a UI update for this control.

Call after changing control state or properties. The control must be attached to a page and not marked as frozen.

will_unmount

will_unmount()

Called before the control is removed from the page tree.

Override to dispose resources created in did_mount(), such as subscriptions, timers, or external handles.