Skip to content

bug: Declarative app: When child controls don't have unique keys, the list is displayed incorrectly after deleting an item #5736

@InesaFitsner

Description

@InesaFitsner

Duplicate Check

Describe the bug

In example, each ft.Dismissible is rendered without a unique key. After swiping an item away, the list is displayed with 2 items removed instead of one. The issue is fixed if uncomment key.

Code sample

Code
import flet as ft


@ft.component
def App():
    items, set_items = ft.use_state(list(range(5)))

    return ft.ListView(
        controls=[
            ft.Dismissible(
                # key=i,
                content=ft.ListTile(title=ft.Text(f"Item {i}")),
                dismiss_direction=ft.DismissDirection.HORIZONTAL,
                background=ft.Container(bgcolor=ft.Colors.GREEN),
                secondary_background=ft.Container(bgcolor=ft.Colors.RED),
                on_dismiss=lambda e, index=i: set_items(
                    [item for item in items if item != index]
                ),
                dismiss_thresholds={
                    ft.DismissDirection.HORIZONTAL: 0.1,
                    ft.DismissDirection.START_TO_END: 0.1,
                },
            )
            for i in items
        ],
    )


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

To reproduce

  1. run example
  2. swipe to dismiss any item -> the dismissed row vanishes momentarily, as well as the other row that should stay

Expected behavior

once an item is dismissed, the remaining tiles realign to match the updated items state.

Screenshots / Videos

Captures

[Upload media here]

Operating System

macOS

Operating system details

macOS

Flet version

0.69.0

Regression

No, it isn't

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