bug: find_by_key() does not find Tab or PopupMenuItem controls by key
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #6976 của @RezaShamsipour — đã merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 65/100
Hướng nghiên cứu
Start with TabControl._keyFromControl in controls/tabs.dart and buildPopupMenuEntries in utils/popup_menu.dart; the typed-key logic in control_widget.dart shows the pattern to reuse. Reproduce with the tests/test_keys.py sample via flet test linux --verbose. Done when find_by_key returns a count of 1 for tab-second and menu-item, and the existing button lookup still passes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Duplicate Check
- I have searched the opened issues and there are no duplicates
Describe the bug
In integration tests, Tester.find_by_key() returns no match for a key set on ft.Tab or ft.PopupMenuItem. Keys set on other controls, for example ft.Button, are found as expected.
Code sample
Code
# src/main.py
import flet as ft
def main(page: ft.Page):
page.add(
ft.Tabs(
length=2,
content=ft.TabBar(
tabs=[
ft.Tab(label="First", key="tab-first"),
ft.Tab(label="Second", key="tab-second"),
]
),
),
ft.PopupMenuButton(
key="menu",
items=[ft.PopupMenuItem(content="Item", key="menu-item")],
),
ft.Button("Button", key="button"),
)
ft.run(main)
# tests/test_keys.py
import flet.testing as ftt
async def test_tab_key(flet_app: ftt.FletTestApp):
tester = flet_app.tester
await tester.pump_and_settle()
assert (await tester.find_by_key("button")).count == 1 # passes
assert (await tester.find_by_key("tab-second")).count == 1 # fails: 0
async def test_popup_menu_item_key(flet_app: ftt.FletTestApp):
tester = flet_app.tester
await tester.pump_and_settle()
await tester.tap(await tester.find_by_key("menu"))
await tester.pump_and_settle()
assert (await tester.find_by_key("menu-item")).count == 1 # fails: 0
To reproduce
- Create a project with
src/main.pyandtests/test_keys.pyfrom the code sample. - Run
flet test linux --verbose. - In
test_tab_key, thebuttonkey is found, butfind_by_key("tab-second")returns a count of 0. - In
test_popup_menu_item_key, after opening the menu,find_by_key("menu-item")returns a count of 0.
Expected behavior
find_by_key() finds Tab and PopupMenuItem controls by their key, the same way it finds other controls.
Screenshots / Videos
Captures
[Upload media here]
Operating System
Linux
Operating system details
Ubuntu 24.04 on WSL2
Flet version
1.0.4
Regression
I'm not sure / I don't know
Suggestions
controls/tabs.dart: TabControl._keyFromControl returns ValueKey(controlKey.value). Because controlKey.value is typed as Object, this creates a ValueKey<Object>, which is not equal to the ValueKey<String> used by find_by_key(). ControlWidget already handles this by creating a typed key (see the comment in control_widget.dart), but TabControl does not use that logic.
utils/popup_menu.dart: buildPopupMenuEntries does not pass the item's key to the Flutter PopupMenuItem or CheckedPopupMenuItem.
Reusing the typed-key logic from ControlWidget in both places should fix this. This is still the case on the main branch.
Logs
Logs
=================================== FAILURES ===================================
_________________________________ test_tab_key _________________________________
flet_app = <flet.testing.flet_test_app.FletTestApp object at 0x7f575f1ad400>
async def test_tab_key(flet_app: ftt.FletTestApp):
tester = flet_app.tester
await tester.pump_and_settle()
assert (await tester.find_by_key("button")).count == 1 # passes
> assert (await tester.find_by_key("tab-second")).count == 1 # fails: 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E assert 0 == 1
E + where 0 = Finder(id=1, count=0, index=0).count
tests/test_keys.py:8: AssertionError
___________________________ test_popup_menu_item_key ___________________________
flet_app = <flet.testing.flet_test_app.FletTestApp object at 0x7f575f1b5a90>
async def test_popup_menu_item_key(flet_app: ftt.FletTestApp):
tester = flet_app.tester
await tester.pump_and_settle()
await tester.tap(await tester.find_by_key("menu"))
await tester.pump_and_settle()
> assert (await tester.find_by_key("menu-item")).count == 1 # fails: 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E assert 0 == 1
E + where 0 = Finder(id=1, count=0, index=0).count
tests/test_keys.py:16: AssertionError
=========================== short test summary info ============================
FAILED tests/test_keys.py::test_tab_key - assert 0 == 1
FAILED tests/test_keys.py::test_popup_menu_item_key - assert 0 == 1
========================= 2 failed in 73.11s (0:01:13) =========================
Additional details
Workaround: set the key on a Text control used as the label or content, for example ft.Tab(label=ft.Text("Second", key="tab-second")) or ft.PopupMenuItem(content=ft.Text("Item", key="menu-item")). find_by_key() then finds the control and tapping it works.
Unrelated side note: Python 3.15.0 was released on October 9, 2026, but flet build and flet test in Flet 1.0.4 only support Python 3.12 to 3.14 (python-build release 20260921). Projects with requires-python >= 3.15 cannot be built or tested yet. Support for 3.15 would be appreciated.
- Ngôn ngữ chính
- Python
- Star
- 17.5k
- Fork
- 740
- Merge trung bình
- 1 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 65
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của flet-dev/flet
-
feature: python 3.15 supportĐang mởfeature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
flet-dev/flet#6985 · 3 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug: `use_state` with a callable initializer is inferred ambiguously by ty and mypyCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
flet build: common [tool.flet.deep_linking] is ignored on Android and iOSCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug packaging platform: mobile
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug: flet-audio on Android: starting one `Audio` permanently pauses any other playing `Audio`Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của flet-dev/flet
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
aws/sagemaker-python-sdk#6554 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
huggingface/diffusers#15170 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] LLM conflict check ignores MNEMOSYNE_LLM_MAX_TOKENS, so reasoning models return empty repliesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
mnemosyne-oss/mnemosyne#1325 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement meshtastic-2.8
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
pskillen/meshflow-api#459 ·