Skip to content
Blog

Implementing Touch-Friendly Drag-and-Drop with LongPressDraggable in Flutter

Master LongPressDraggable in Flutter to build touch-friendly drag-and-drop user interfaces without triggering unintended scroll operations on mobile devices.

Published on • November 9, 2026

AI Assistant

Building drag-and-drop UIs on mobile devices presents a unique gesture collision challenge: standard touch dragging (Draggable) often conflicts with vertical list scrolling or swipe gestures.

Flutter solves this problem with LongPressDraggable. By requiring a slight press-and-hold gesture before initializing the drag operation, touch users can scroll through lists normally while retaining intuitive reordering capabilities.

Understanding LongPressDraggable Components

Like standard Draggable, LongPressDraggable<T> works together with a DragTarget<T>. It accepts a data payload of type T and requires three visual widgets:

  1. child: The idle widget rendered in its original position.
  2. feedback: The floating widget displayed directly under the user’s touch point during dragging.
  3. childWhenDragging: The placeholder widget left behind in the original slot while dragging is active.
import 'package:flutter/material.dart';

class TaskItem {
  final String id;
  final String title;

  TaskItem({required this.id, required this.title});
}

class TaskCard extends StatelessWidget {
  final TaskItem task;

  const TaskCard({super.key, required this.task});

  @override
  Widget build(BuildContext context) {
    return LongPressDraggable<TaskItem>(
      data: task,
      hapticFeedbackOnStart: true, // Vibrates device on drag activation
      feedback: Material(
        elevation: 8,
        borderRadius: BorderRadius.circular(8),
        child: Container(
          width: 200,
          padding: const EdgeInsets.all(16),
          color: Colors.indigo.shade400,
          child: Text(
            task.title,
            style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
          ),
        ),
      ),
      childWhenDragging: Opacity(
        opacity: 0.3,
        child: _buildCardUI(Colors.grey.shade300),
      ),
      child: _buildCardUI(Colors.white),
    );
  }

  Widget _buildCardUI(Color color) {
    return Container(
      padding: const EdgeInsets.all(16),
      margin: const EdgeInsets.symmetric(vertical: 4),
      decoration: BoxDecoration(
        color: color,
        borderRadius: BorderRadius.circular(8),
        border: Border.all(color: Colors.grey.shade300),
      ),
      child: Text(task.title),
    );
  }
}

Receiving Data with DragTarget

The DragTarget<T> acts as the drop zone. It receives lifecycle callbacks (onWillAcceptWithDetails, onAcceptWithDetails, onLeave) to update visual cues and handle state changes when items are dropped.

class KanbanColumn extends StatefulWidget {
  final String title;
  final List<TaskItem> tasks;
  final Function(TaskItem) onTaskDropped;

  const KanbanColumn({
    super.key,
    required this.title,
    required this.tasks,
    required this.onTaskDropped,
  });

  @override
  State<KanbanColumn> createState() => _KanbanColumnState();
}

class _KanbanColumnState extends State<KanbanColumn> {
  bool _isHovering = false;

  @override
  Widget build(BuildContext context) {
    return DragTarget<TaskItem>(
      onWillAcceptWithDetails: (details) {
        setState(() => _isHovering = true);
        return true;
      },
      onLeave: (_) {
        setState(() => _isHovering = false);
      },
      onAcceptWithDetails: (details) {
        setState(() => _isHovering = false);
        widget.onTaskDropped(details.data);
      },
      builder: (context, candidateData, rejectedData) {
        return Container(
          width: 260,
          padding: const EdgeInsets.all(12),
          decoration: BoxDecoration(
            color: _isHovering ? Colors.indigo.shade50 : Colors.grey.shade100,
            borderRadius: BorderRadius.circular(12),
            border: Border.all(
              color: _isHovering ? Colors.indigo : Colors.transparent,
              width: 2,
            ),
          ),
          child: Column(
            children: [
              Text(
                widget.title,
                style: const TextStyle(fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 12),
              ...widget.tasks.map((task) => TaskCard(task: task)),
            ],
          ),
        );
      },
    );
  }
}

Practical UX Enhancements

  1. Haptic Feedback: Set hapticFeedbackOnStart: true on LongPressDraggable to give the user physical tactile verification when the long-press gesture resolves into a drag.
  2. Axis Constraints: Use the axis property (e.g., Axis.horizontal or Axis.vertical) if you want to restrict drag movement along a single line.
  3. Delay Configuration: Customize the press duration using delay (defaults to kLongPressTimeout, ~500ms).

Takeaway: LongPressDraggable is the gold standard for mobile touch-based drag-and-drop, avoiding scroll-gesture collisions while offering precise user control.