flame icon indicating copy to clipboard operation
flame copied to clipboard

fix!: onDragCancel should not delegate to onDragEnd by default

Open rumitvn opened this issue 5 months ago • 0 comments

DragCallbacks.onDragCancel delegates to onDragEnd by default:

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

But the two events mean different things. onDragEnd is the natural end of a drag and carries velocity for fling detection; onDragCancel means the gesture was interrupted (another recognizer won the arena, a second pointer triggered a scale takeover, a system event, etc.) and has no meaningful velocity. Forwarding a cancel to onDragEnd makes a drag-to-dismiss component apply its action when the drag was actually cancelled. The old "very rare event" comment is also no longer true: with MultiDragScaleDispatcher every two-finger pinch cancels the individual pointer drags.

This changes onDragCancel to just reset isDragged (the same state onDragEnd clears) without forwarding. Anyone who wants the old behavior can override onDragCancel and call onDragEnd themselves, as the updated doc comment notes.

Breaking change, so the commit is prefixed fix!:. I updated doc/flame/inputs/drag_events.md, adjusted the two existing tests that asserted the delegation, and added a test that isolates the new behavior (cancel resets isDragged and does not fire onDragEnd). melos-style local run of the affected suites:

flutter test test/events/component_mixins/drag_callbacks_test.dart test/events/component_mixins/scale_drag_callbacks_test.dart
00:00 +42: All tests passed!
dart analyze (changed files): No issues found!

Closes #3926

rumitvn avatar Jun 15 '26 15:06 rumitvn