Skip to content

bug: Making custom controls through the @control decorator does not allow you to set callback functions #6488

@Qye-Leisure

Description

@Qye-Leisure

Duplicate Check

Describe the bug

When using @control decorator in a flet, when creating a custom control, an incoming event callback will directly report an error

Code sample

Code
import flet as ft
from typing import Optional,Callable

@ft.control
class ceshi(ft.Container):
    expand :bool | int | None=True
    bgcolor:ft.Colors=ft.Colors.BLUE_100
    click_callback: Optional[Callable] =  None

    def init(self):
        # self._click_callback,self.click_callback=self.click_callback,None
        self.on_click=self._on_click

    def _on_click(self,e):
        
        print(f"aaa==={e}")

        if self.click_callback is not None:
            self.click_callback(e)

        # if self._click_callback is not None:
        #     self._click_callback(e)

if __name__ == "__main__":
    def main(page:ft.Page):

        aaa=ceshi(
            click_callback=lambda e :print(f"click_callback_AAA====:{e}")
        )

        page.add( aaa )

    ft.run(main)

To reproduce

Run directly

Expected behavior

I hope that callback functions can be used normally, or that there is a way to use callback functions normally.

Screenshots / Videos

Captures

[Upload media here]

Image

Operating System

Windows

Operating system details

win11

Flet version

0.85

Regression

No, it isn't

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions