Skip to main content

BaseControl

Base class for all Flet controls and services.

Properties

  • data - Arbitrary data of any type.
  • key - A stable key used to preserve control identity across updates.
  • 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.
  • get_data_channel - Resolve the [DataChannel] allocated on the Dart side for this widget.
  • 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: KeyValue | None = None

A stable key used to preserve control identity across updates.

pageproperty

page: Page | BasePage

The page to which this control belongs to.

parentproperty

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.

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.

get_data_channel

get_data_channel(channel_id: int)

Resolve the [DataChannel] allocated on the Dart side for this widget. Pattern:

on_data_channel_open: Optional[ft.EventHandler[DataChannelOpenEvent]] = None

def init(self): self.on_data_channel_open = self._on_open

def _on_open(self, e): self._channel = self.get_data_channel(e.channel_id)

Idempotent — the underlying Connection caches DataChannels by id, so repeated calls return the same instance. No error path: the id always comes from a framework-fired event, so by the time this runs the channel exists on both sides.

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

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.