DavideBelsole / great_list_view

pub.dev library for flutter
MIT License
41 stars 22 forks source link

How can I limit drag&drop to a specific position range? #16

Closed mregnauld closed 2 years ago

mregnauld commented 2 years ago

In my project, I have a list of 100 items, all reorderable, except the first 2 items. I need 2 things:

How can I achieve that?

Thanks.

mregnauld commented 2 years ago

OK, so here is how I managed to achieve that: use the reorderModel attribute of AutomaticAnimatedListView:

AutomaticAnimatedListView<ItemData>(
  reorderModel: AnimatedListReorderModel(
    onReorderStart: (index, dx, dy) {
      return index > 1;
    },
    onReorderMove: (index, dropIndex) {
      return index > 1;
    },
    onReorderComplete: (index, dropIndex, slot) {
      if (dropIndex > 1)
      {
        currentList.insert(dropIndex, currentList.removeAt(index));
        return true;
      }
      return false;
    }
  ),
  ...
)