如何使Flutter上的按钮/图标按下可拖动的ReorderableListView ListTile?

Joh*_*Boy 6 draggable flutter

所以我看了ReorderableListView演示,看到他们有

“第二:const Icon(Icons.drag_handle)”

但是在查看reorderable_list.dart文件时,我注意到整个列表仍然可以在LongPressDraggable上拖动[第424行]。所以,我怎么能明确作出任何的源代码或适当改变我自己,为了使图标的实际拖动手柄?

CheckboxListTile(
      key: Key(item.value),
      isThreeLine: true,
      value: item.checkState ?? false,
      onChanged: (bool newValue) {
        setState(() {
          item.checkState = newValue;
        });
      },
      title: Text('This item represents ${item.value}.'),
      subtitle: secondary,
      secondary: const Icon(Icons.drag_handle),  // Make this Icon drag source
    );
Run Code Online (Sandbox Code Playgroud)

谢谢

Roc*_*ice 14

2021/05/29

作为答案的更新,已经有一个可自定义的处理程序ReorderableListView

随着最近对 ReorderableListView 的重构(PR:#74299 和 #74697),我们在桌面上运行时添加了自动拖动手柄(使用 buildDefaultDragHandles 属性将其关闭)。如果这不是您想要的,您可以将自己的拖​​动手柄作为小部件添加到每个项目中,如下所示:

ReorderableDragStartListener(
  index: index,
  child: const Icon(Icons.drag_handle),
),
Run Code Online (Sandbox Code Playgroud)

您可以在这里查看详细信息:https ://github.com/flutter/flutter/issues/46805


Feu*_*Feu 11

我认为Icon(Icons.drag_handle)这只是为了那里的外观,要将项目拖入ReorderableListView您必须长按它。

您可以使用flutter_reorderable_list并实现这一目标。正如你在它的演示中看到的,这个插件按照你想要的方式工作。

但是,它的工作方式完全不同ReorderableListView,代码更改可能有点令人不知所措。我创建了一个小部件来简化该开关,小部件在此处,其演示在此处

如果它适合您的用例,请查看并使用它。