huhuang03 / reorderable_grid_view

MIT License
46 stars 32 forks source link

How to disable drag on some items of the grid ? #72

Open kristijorgji opened 9 months ago

kristijorgji commented 9 months ago

Hi,

we have a grid of 12 items, some of them have photos other are empty.

We want to allow only the items that have photos to be draggable and dropped only on other items that have photos as well!

Items that are just placeholders shouldn't move or be draggable. (example while uploading photos in dating or social apps like Tinder)

How to achieve this? (we know the indexes of the items that are empty and want to disable from the drag&drop mechanism)

huhuang03 commented 9 months ago

The current API design is not very good.

You can see https://github.com/huhuang03/reorderable_grid_view/blob/master/example/lib/demo/demo_custom.dart.

The key is:

  1. Use a ReorderableWrapperWidget as a wrapper for your real GridView
  2. Wrap reorderable child in ReorderableItemView
  3. The ReorderableItemView index param shoud in order for all ReorderableItemView items.
kristijorgji commented 9 months ago

@huhuang03 thanks a lot for the reply.

I checked the provided code but don't understand how to disable from the d&d mechanism a particular index.

Let say I want indeces 2,4 from my 9 items grid (0-8) to be disabled (not draggable, not targets and not moving around when other items drag and drop)

How can I do that ?

huhuang03 commented 9 months ago

Hello. you can try version 2.2.9-alpha.1. And do like https://github.com/huhuang03/reorderable_grid_view/blob/555e135b1b79c7bc21bd2cd7fc691f6cd9effbfa/example/lib/demo/demo_drag_enable_config.dart.