Skip to content

Conversation

shebnik
Copy link

@shebnik shebnik commented Jun 25, 2025

This PR introduces a new boolean property, addDragStartListener. When set to false, the ReorderableGridDragStartListener will not be injected, allowing to listen to item builder children tap events and wrap own widgets (e.g. a “burger” icon) with ReorderableGridDragStartListener at any desired location inside item builder, which can be used to edit list order.

This closes the issue #132 requesting support for custom drag handles:

“Please provide a way to use ReorderableGridDragStartListener with custom widget, … when by design we want to drag only with specific burger icon instead of full item widget.”

Changes:

  • New API

    /// Whether to add a [ReorderableGridDragStartListener] to the reorderable ItemBuilder.
    /// 
    /// Defaults to true.
    /// 
    /// If set to false, the items in ItemBuilder will not respond to pointer down events,
    /// which means they won't be draggable. This can be useful if you still want to
    /// receive item pointer events, and add your custom drag start listener
    /// to the item widget.
    /// 
    /// Example:
    /// ```dart
    /// ReorderableGridDragStartListener(
    ///   index: dragIndex,
    ///   child: const Icon(
    ///     Icons.drag_handle_outlined,
    ///   ),
    /// ),
    /// ```
    final bool addDragStartListener;
  • Constructor default:
    Sets addDragStartListener = true to preserve existing behavior.

  • reorderableItemBuilder:

    • If addDragStartListener == false, simply returns the item, without ReorderableGridDragStartListener.
    • Otherwise, retains existing logic, whole item is draggable.

Usage Example:

AnimatedReorderableListView(
  items: items,
  addDragStartListener: false, // disable drag listener
  itemBuilder: (context, index) {
    final item = items[index];
    return ListTile(
      title: Text(item.title),
      onTap: () {
        // Handle item tap, if needed
      },
      trailing: ReorderableGridDragStartListener(
        index: index,
        child: Icon(Icons.drag_handle), // custom handle
      ),
    );
  },
  onReorder: (int oldIndex, int newIndex) {
    setState(() {
      final item = items.removeAt(oldIndex);
      items.insert(newIndex, item);
    });
   },
   isSameItem: (a, b) => a.id == b.id,
);

Local Testing / Preview

To try out this PR, point your pubspec.yaml at the Git branch:

dependency_overrides:
  animated_reorderable_list:
    git:
      url: https://github.com/shebnik/animated_reorderable_list.git
      ref: fix-item-tap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant