Closed rulerofthehuns closed 1 year ago
What the purpose of using key
property?
It seems to be some kind of ID, but I haven't found it in the documentation. I use it to find a control with a specific key in a page.
It's not 'private' and has a setter property, so changing it should not cause this issue.
I've got the idea from here: https://docs.flutter.dev/cookbook/testing/widget/finders#2-find-a-widget-with-a-specific-key
@FeodorFitsner, there seems to be a great issue. Try this:
import flet as ft
def main(page: ft.Page):
page.theme_mode = "light"
page.add(
ft.ListView(
controls=[
ft.TextField(
key=None
),
ft.TextField(
key="2"
),
ft.TextField(
key="3"
)
]
)
)
ft.app(
target=main,
# view=ft.WEB_BROWSER
)
Try typing some text in each of the fields (the last two to be more precise) and you will notice that the focus is not only lost by these last two when typing in a character(as mentioned by @rulerofthehuns), but it is always given to the first one. That really not good. Hope you see what I mean...
Feels like we need to rename that property to scroll_key
to avoid confusion?
Yeah, I think too. And precise in the docs that it shouldn't be used to globally identify controls.
Nevertheless @FeodorFitsner, the error I mentioned above will still exist!
Wow! I lost hours yesterday chasing the mysterious reason for this loss of focus on text fields!!! thanks to this issue I now fixed my problems! I am now using data attribute, which by the way is not documented.
If the 'key' property of a TextField instance is not null, textfield loses focus after each typed character. Seems to work file if 'key' is None
Code example to reproduce the issue:
Describe the results you received: Click in textfield, start typing, keyboard focus disappears after 1 character. Happens with or without 'view=ft.WEB_BROWSER'
Describe the results you expected: Be able to type
Additional information you deem important (e.g. issue happens only occasionally):
Flet version (
pip show flet
):Operating system: Windows
Additional environment details: