flame icon indicating copy to clipboard operation
flame copied to clipboard

fix: onDragCancel should not delegate to onDragEnd by default

Open spydon opened this issue 6 months ago • 1 comments

Problem

DragCallbacks.onDragCancel currently delegates to onDragEnd by default:

void onDragCancel(DragCancelEvent event) => onDragEnd(event.toDragEnd());

These two events are semantically different:

  • onDragEnd: the user lifted their finger naturally; carries velocity info for fling detection.
  • onDragCancel: the gesture was interrupted (another recognizer won the arena, a second finger caused a scale takeover, a system event, etc.); no meaningful velocity.

Calling onDragEnd from onDragCancel conflates the two. A drag-to-dismiss component would incorrectly "apply the action" when the drag was actually cancelled. Calls from cancel always produce zero velocity in DragEndDetails, which can cause subtle bugs.

The comment in the source calls cancellations "very rare", but with MultiDragScaleDispatcher (PR #3782) this is no longer true: every two-finger pinch gesture cancels the individual pointer drags.

Proposed fix

  • onDragCancel should reset isDragged directly (the same way onDragEnd does) without forwarding to onDragEnd.
  • Users who want identical handling can override onDragCancel to call onDragEnd themselves.

Impact

This is a breaking change: existing code that relies on onDragCancel triggering onDragEnd will need to be updated.

Related to #1938.

spydon avatar May 17 '26 14:05 spydon

Opened #3934 implementing this — onDragCancel now resets isDragged directly instead of forwarding to onDragEnd, with the doc comment and the two delegation-asserting tests updated and a new test isolating the behavior. Marked breaking (fix!:) as you noted.

rumitvn avatar Jun 15 '26 15:06 rumitvn