marcojakob / dart-dnd

Drag and Drop for Dart web apps with mouse and touch support.
https://code.makery.ch/library/dart-drag-and-drop/
MIT License
135 stars 86 forks source link

How to make new item also draggable? #32

Open warenix opened 5 years ago

warenix commented 5 years ago

Initially I have a table of 4 rows, and I initialized Draggable once.

    Draggable(tableElement, avatarHandler: AvatarHandler.clone());

    Dropzone dropzone = Dropzone(stationListElement);

    dropzone.onDrop.listen((DropzoneEvent event) {
      _reorder(event.draggableElement, event.dropzoneElement);
    });

Later the component added a new row after some user interaction.

Problem is that new row isn't draggable. I tried initialize again but the drop event is listened twice.

Do you have any suggestion how to handle it on my use case?

marcojakob commented 5 years ago

At the moment this use case is not handled very nice. You could try to create a new draggable for each new element but I'm not sure if that will work and if it will not have unwanted side-effects like unnecessary listeners for the same event.

I think it's a valid use case. We could change the structure in draggable.dart and draggable_manager.dart to allow adding new elements. The Draggable could still have an initial list of elements in the constructor but in addition get a new method to later add elements.

If you (or anyone else) wants to have a go at it, I think I could assist and should find time to review a pull request.