What’s LongPressDraggable?

The LongPressDraggable class in Flutter allows its child widget to be dragged starting from a long press. It is similar to the Draggable class, but the drag action is initiated after a long press instead of immediately.

Check the official documentation for more.

LongPressDraggable explained for Android Developers

For Android developers familiar with drag-and-drop functionality, the LongPressDraggable class can be compared to the GestureDetector in Android, which detects gestures like long presses. In Jetpack Compose, similar functionality can be achieved using Modifier.draggable, but LongPressDraggable provides a more straightforward approach for initiating drags with a long press.

Example Code

Here is an example of how to use LongPressDraggable:

LongPressDraggable(
child: Container(
color: Colors.blue,
width: 100,
height: 100,
),
feedback: Container(
color: Colors.red,
width: 100,
height: 100,
),
onDragStarted: () {
print('Drag started');
},
onDragCompleted: () {
print('Drag completed');
},
onDraggableCanceled: (velocity, offset) {
print('Drag canceled');
},
)

LongPressDraggable Remarks

The LongPressDraggable class simplifies the implementation of drag-and-drop functionality in Flutter applications, making it easier for developers to create interactive user interfaces.

Bootstrap Your app with ShipFlutter

A fully customizable starter kit to seamlessly launch responsive Android, iOS, and Web apps with Flutter powered by Firebase and Vertex AI.