Skip to content

Commit 3409085

Browse files
Control.parent property (#2906)
* initial commit * remove parent when unmounting * update parent typing * set parent when adding/replacing --------- Co-authored-by: Feodor Fitsner <[email protected]>
1 parent d21c512 commit 3409085

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

sdk/python/packages/flet-core/src/flet_core/control.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(
4646
self.__data: Any = None
4747
self.data = data
4848
self.__event_handlers = {}
49+
self.parent: Optional[Control] = None
4950
if ref:
5051
ref.current = self
5152

@@ -418,6 +419,7 @@ def build_update_commands(
418419
index=index, added_controls=added_controls
419420
)
420421
assert self.__uid is not None
422+
ctrl.parent = self # set as parent
421423
commands.append(
422424
Command(
423425
indent=0,
@@ -447,6 +449,7 @@ def build_update_commands(
447449
index=index, added_controls=added_controls
448450
)
449451
assert self.__uid is not None
452+
ctrl.parent = self # set as parent
450453
commands.append(
451454
Command(
452455
indent=0,
@@ -515,6 +518,7 @@ def _build_add_commands(self, indent=0, index=None, added_controls=None):
515518
indent=indent + 2, index=index, added_controls=added_controls
516519
)
517520
commands.extend(childCmd)
521+
control.parent = self # set as parent
518522

519523
self.__previous_children.clear()
520524
self.__previous_children.extend(children)

sdk/python/packages/flet-core/src/flet_core/page.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ def __update_control_ids(self, added_controls, results):
455455
def __handle_mount_unmount(self, added_controls, removed_controls):
456456
for ctrl in removed_controls:
457457
ctrl.will_unmount()
458+
ctrl.parent = None # remove parent reference
458459
ctrl.page = None
459460
for ctrl in added_controls:
460461
ctrl.did_mount()

0 commit comments

Comments
 (0)