DavideBelsole / great_list_view

pub.dev library for flutter
MIT License
39 stars 21 forks source link

DragListener Widget #36

Open MSOB7YY opened 1 year ago

MSOB7YY commented 1 year ago

is there any widget wrapper that acts as a listener for drags? just like flutter's ReorderableDragStartListener

dodatw commented 1 year ago

same here

martipello commented 1 year ago

yes they allow you to use the controller to implement your own drag handle, wrap your handle in a gesture detector, pass it the animation controller and implement the methods for dragging events

onVerticalDragStart: (dd) { controller.notifyStartReorder( context, dd.localPosition.dx, dd.localPosition.dy, ); }, onVerticalDragUpdate: (dd) { controller.notifyUpdateReorder( dd.localPosition.dx, dd.localPosition.dy, ); }, onVerticalDragEnd: (dd) { controller.notifyStopReorder(false); }, onVerticalDragCancel: () { controller.notifyStopReorder(true); },

yairsts commented 11 months ago

Hi, You can override the reorderModel, just create your own AutomaticAnimatedListReorderModel:

class MyReorderModel<T> extends AnimatedListBaseReorderModel {
  const MyReorderModel(this.list, {this.onReorder});

  final List<T> list;
  final Function(List<T>)? onReorder;

  @override
  bool onReorderStart(int index, double dx, double dy) => true;

  @override
  Object? onReorderFeedback(int index, int dropIndex, double offset, double dx, double dy) => null;

  @override
  bool onReorderMove(int index, int dropIndex) => true;

  @override
  bool onReorderComplete(int index, int dropIndex, Object? slot) {
    list.insert(dropIndex, list.removeAt(index));

    //=====when the reorder complete, you call reorderCallback=====
    onReorder?.call(list);

    return true;
  }
}