Skip to content

bug: RuntimeError: Frozen controls cannot be updated. #5841

@aigcst

Description

@aigcst

Duplicate Check

Describe the bug

The previous modes cannot be mixed in the Declarative UI.
#5342 Many of the contents inside have changed

Code sample

Code Code that runs normally
import flet as ft


@ft.component
def App():
    count, set_count = ft.use_state(0)
    is_hoved, set_is_hoved = ft.use_state(0)

    def change_color(e):
        set_is_hoved(not is_hoved)

    return ft.Row(
        controls=[
            ft.Text(value=f"{count}"),
            ft.Button(
                "Add",
                bgcolor=ft.Colors.BLUE if is_hoved else ft.Colors.RED,
                on_click=lambda: set_count(count + 1),
                on_hover=change_color,
            ),
        ],
    )


ft.run(lambda page: page.render(App))

Code that throws an error when hovered over

import flet as ft


@ft.component
def App():
    count, set_count = ft.use_state(0)

    def change_color(e):
        e.control.bgcolor = ft.Colors.BLUE if e.data else ft.Colors.RED

    return ft.Row(
        controls=[
            ft.Text(value=f"{count}"),
            ft.Button(
                "Add",
                bgcolor=ft.Colors.RED,
                on_click=lambda: set_count(count + 1),
                on_hover=change_color,
            ),
        ],
    )


ft.run(lambda page: page.render(App))

To reproduce

Steps to reproduce:
1.Run the repro code.
2.When hovering over the button, an error is reported: RuntimeError: Frozen controls cannot be updated.

Expected behavior

Can imperative UI be used normally in Declarative UI (or can they be mixed and used)? I expect both forms to work properly.

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

windows 11

Flet version

0.70.0.dev6735

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions