How do I make a ReorderableListView ListTile draggable on button/icon press for Flutter?

筅森魡賤 提交于 2021-02-08 12:25:10

问题


So I saw the ReorderableListView demo and saw that they had the

"secondary: const Icon(Icons.drag_handle)"

but looking at the reorderable_list.dart file, I noticed that the entire list was draggable on LongPressDraggable anyway [line 424]. So how can I explicitly make changes to either the source code or my own, in order to properly make the icon an actual drag handle?

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
    );

Thanks


回答1:


I think the Icon(Icons.drag_handle) it's just for the looks there, to drag the item in a ReorderableListView you have to long press it.

You can use flutter_reorderable_list and achieve that. As you can see in its demo, this plugin works just the way you want to.

However, it works quite differently of ReorderableListView, the code change can be a bit overwhelming. I created a Widget to simplify that switch, the widget is here and its demo is here.

Take a look and use it if it fits your use case.



来源:https://stackoverflow.com/questions/53201483/how-do-i-make-a-reorderablelistview-listtile-draggable-on-button-icon-press-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!