Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pointer events #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/drag_and_drop_builder_parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart';
typedef void OnPointerMove(PointerMoveEvent event);
typedef void OnPointerUp(PointerUpEvent event);
typedef void OnPointerDown(PointerDownEvent event);
typedef void OnPointerCancel(PointerCancelEvent event);
typedef void OnItemReordered(
DragAndDropItem reorderedItem,
DragAndDropItem receiverItem,
Expand All @@ -26,6 +27,7 @@ class DragAndDropBuilderParameters {
final OnPointerMove? onPointerMove;
final OnPointerUp? onPointerUp;
final OnPointerDown? onPointerDown;
final OnPointerCancel? onPointerCancel;
final OnItemReordered? onItemReordered;
final OnItemDropOnLastTarget? onItemDropOnLastTarget;
final OnListReordered? onListReordered;
Expand Down Expand Up @@ -64,6 +66,7 @@ class DragAndDropBuilderParameters {
this.onPointerMove,
this.onPointerUp,
this.onPointerDown,
this.onPointerCancel,
this.onItemReordered,
this.onItemDropOnLastTarget,
this.onListReordered,
Expand Down
1 change: 1 addition & 0 deletions lib/drag_and_drop_list_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class _DragAndDropListWrapper extends State<DragAndDropListWrapper>
onPointerMove: _onPointerMove,
onPointerDown: widget.parameters.onPointerDown,
onPointerUp: widget.parameters.onPointerUp,
onPointerCancel: widget.parameters.onPointerCancel,
),
];

Expand Down
17 changes: 17 additions & 0 deletions lib/drag_and_drop_lists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ class DragAndDropLists extends StatefulWidget {
/// https://github.com/flutter/flutter/issues/14842#issuecomment-371344881
final bool removeTopPadding;

/// Respond to the DragAndDropLists' onPointerMove event. This exists to work
/// around a conflict in the Flutter engine where multiple Listeners at
/// different levels in the widget hierarchy cannot work together.
final OnPointerMove? listsOnPointerMove;

/// Respond to the DragAndDropLists' onPointerCancel event. This exists to
/// work around a conflict in the Flutter engine where multiple Listeners at
/// different levels in the widget hierarchy cannot work together.
final OnPointerCancel? listsOnPointerCancel;

DragAndDropLists({
required this.children,
required this.onItemReorder,
Expand Down Expand Up @@ -336,6 +346,8 @@ class DragAndDropLists extends StatefulWidget {
this.itemDragHandle,
this.constrainDraggingAxis = true,
this.removeTopPadding = false,
this.listsOnPointerMove,
this.listsOnPointerCancel,
Key? key,
}) : super(key: key) {
if (listGhost == null &&
Expand Down Expand Up @@ -394,6 +406,7 @@ class DragAndDropListsState extends State<DragAndDropLists> {
onPointerDown: _onPointerDown,
onPointerUp: _onPointerUp,
onPointerMove: _onPointerMove,
onPointerCancel: widget.listsOnPointerCancel,
onItemReordered: _internalOnItemReorder,
onItemDropOnLastTarget: _internalOnItemDropOnLastTarget,
onListReordered: _internalOnListReorder,
Expand Down Expand Up @@ -680,6 +693,10 @@ class DragAndDropListsState extends State<DragAndDropLists> {

_scrollList();
}

if (widget.listsOnPointerMove != null) {
widget.listsOnPointerMove!(event);
}
}

_onPointerDown(PointerDownEvent event) {
Expand Down