onHorizontalDragEnd method

GestureDetector onHorizontalDragEnd(
  1. GestureDragEndCallback onHorizontalDragEnd, {
  2. HitTestBehavior? behavior,
  3. bool excludeFromSemantics = false,
  4. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  5. bool trackpadScrollCausesScale = false,
  6. Offset trackpadScrollToScaleFactor = kDefaultTrackpadScrollToScaleFactor,
  7. Set<PointerDeviceKind>? supportedDevices,
})

Wraps the widget in a GestureDetector that responds to horizontal drag end events.

This method is called when a horizontal drag gesture ends. It provides information about the final velocity and position, which is useful for implementing momentum scrolling, snap-to-position behavior, carousel page snapping, or other physics-based interactions that should continue after the user lifts their finger.

Parameters:

  • onHorizontalDragEnd: The callback to execute when a horizontal drag ends. Provides DragEndDetails with velocity and position information.
  • behavior: How the gesture detector should behave during hit testing.
  • excludeFromSemantics: Whether to exclude from semantic tree. Defaults to false.
  • dragStartBehavior: When drag gestures should start. Defaults to DragStartBehavior.start.
  • trackpadScrollCausesScale: Whether trackpad scrolling causes scaling. Defaults to false.
  • trackpadScrollToScaleFactor: Scale factor for trackpad scroll conversion.
  • supportedDevices: Set of supported pointer device kinds.

Returns a GestureDetector widget that responds to horizontal drag end events.

Example:

Container(
  width: 200,
  child: Text('Flick me horizontally'),
).onHorizontalDragEnd((details) {
  print('Horizontal drag ended with velocity: ${details.velocity.pixelsPerSecond.dx}');
  // Apply momentum scrolling or snap to page
});

Implementation

GestureDetector onHorizontalDragEnd(
  GestureDragEndCallback onHorizontalDragEnd, {
  HitTestBehavior? behavior,
  bool excludeFromSemantics = false,
  DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  bool trackpadScrollCausesScale = false,
  Offset trackpadScrollToScaleFactor = kDefaultTrackpadScrollToScaleFactor,
  Set<PointerDeviceKind>? supportedDevices,
}) {
  return GestureDetector(
    onHorizontalDragEnd: onHorizontalDragEnd,
    behavior: behavior,
    excludeFromSemantics: excludeFromSemantics,
    dragStartBehavior: dragStartBehavior,
    trackpadScrollCausesScale: trackpadScrollCausesScale,
    trackpadScrollToScaleFactor: trackpadScrollToScaleFactor,
    supportedDevices: supportedDevices,
    child: this,
  );
}