Skip to content

ReorderableDraggable

Used to drag an item in a ReorderableListView.

It creates a listener for a drag immediately following a pointer down event over the given content control.

Example
ft.ReorderableListView(
    expand=True,
    show_default_drag_handles=False,
    controls=[
        ft.ReorderableDraggable(
            index=i,
            content=ft.ListTile(
                title=f"Draggable Item {i}",
                bgcolor=ft.Colors.GREY if i % 2 == 0 else ft.Colors.BLUE_ACCENT,
            ),
        )
        for i in range(10)
    ],
)

Inherits: LayoutControl, AdaptiveControl

Properties

  • content(Control) –

    The control for which the application would like to respond to a tap and

  • index(int) –

    The index of the associated item that will be dragged in the list.

Examples#

Basic Example#

import flet as ft


def main(page: ft.Page):
    def get_color(index: int) -> ft.Colors:
        return ft.Colors.ERROR if index % 2 == 0 else ft.Colors.ON_ERROR_CONTAINER

    page.add(
        ft.ReorderableListView(
            expand=True,
            show_default_drag_handles=False,
            on_reorder=lambda e: print(
                f"Reordered from {e.old_index} to {e.new_index}"
            ),
            controls=[
                ft.ReorderableDraggable(
                    index=i,
                    content=ft.ListTile(
                        title=ft.Text(f"Draggable Item {i}", color=ft.Colors.BLACK),
                        leading=ft.Icon(ft.Icons.CHECK, color=ft.Colors.RED),
                        bgcolor=get_color(i),
                    ),
                )
                for i in range(10)
            ],
        )
    )


ft.run(main)

Properties#

content instance-attribute #

content: Control

The control for which the application would like to respond to a tap and drag gesture by starting a reordering drag on a reorderable list.

Must be visible.

Raises:

index instance-attribute #

index: int

The index of the associated item that will be dragged in the list.