Closed Dzheremi2 closed 2 months ago
hey, bro. This is an incorrect usage. on_click may be set function name or using lambda instead of calling it example:
import flet as ft
def main(page: ft.Page):
def test(e):
for i in range(10):
page.controls.append(ft.Text("Test Text", color=ft.colors.WHITE, size=100))
page.update()
page.floating_action_button = ft.FloatingActionButton(
icon=ft.icons.CHECK_CIRCLE_OUTLINE_OUTLINED,
text="Test",
enable_feedback=True,
on_click=test # You shouldn't call it
)
page.update()
ft.app(main)
hey, bro. This is an incorrect usage. on_click may be set function name or using lambda instead of calling it example:
import flet as ft def main(page: ft.Page): def test(e): for i in range(10): page.controls.append(ft.Text("Test Text", color=ft.colors.WHITE, size=100)) page.update() page.floating_action_button = ft.FloatingActionButton( icon=ft.icons.CHECK_CIRCLE_OUTLINE_OUTLINED, text="Test", enable_feedback=True, on_click=test # You shouldn't call it ) page.update() ft.app(main)
Oh god, thank you so much. I've almost gave up.
Duplicate Check
Describe the bug
I created a FAB and set its
on_click
method to my function.But every time I run my code, this function triggers without pressing the FAB
Code sample
Code
```python import flet as ft def main(page: ft.Page): def test(): for i in range(10): page.controls.append(ft.Text("Test Text", color=ft.colors.WHITE, size=100)) page.floating_action_button = ft.FloatingActionButton( icon=ft.icons.CHECK_CIRCLE_OUTLINE_OUTLINED, text="Test", enable_feedback=True, on_click=test() ) page.update() ft.app(main) ```To reproduce
Just run this code with
flet run [name].py
Expected behavior
test()
function executes only when FAB pressed.Screenshots / Videos
Captures
https://github.com/user-attachments/assets/3fc6c25c-74b1-4b35-af66-7393ac7525d3Operating System
Linux
Operating system details
Linux fedora 6.10.7-200.fc40.x86_64
Flet version
0.24.1
Regression
I'm not sure / I don't know