如何使 ReorderableListView ListTile 在 Flutter 按下 button/icon 时可拖动?
How do I make a ReorderableListView ListTile draggable on button/icon press for Flutter?
所以我看到了 ReorderableListView demo 并且看到他们有
"secondary: 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
);
谢谢
我认为 Icon(Icons.drag_handle)
只是为了美观,要将项目拖到 ReorderableListView
中,您必须长按它。
您可以使用 flutter_reorderable_list 并实现它。正如您在它的演示中看到的那样,这个插件可以按照您想要的方式工作。
但是,它的工作方式与 ReorderableListView
完全不同,代码更改可能有点让人不知所措。我创建了一个小部件来简化该开关,即 widget is here and its demo is here.
看看它是否适合您的用例。
2021/05/29
作为答案的更新,已经有一个可自定义的处理程序 ReorderableListView
:
With the recent refactoring of the ReorderableListView (PRs: #74299 and #74697), we have added automatic drag handles when running on the desktop (with a buildDefaultDragHandles property to turn it off). If this isn't what you want, you can add your own drag handle as a widget to each of your items with something like:
ReorderableDragStartListener(
index: index,
child: const Icon(Icons.drag_handle),
),
您可以在这里查看详细信息:https://github.com/flutter/flutter/issues/46805
所以我看到了 ReorderableListView demo 并且看到他们有
"secondary: 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
);
谢谢
我认为 Icon(Icons.drag_handle)
只是为了美观,要将项目拖到 ReorderableListView
中,您必须长按它。
您可以使用 flutter_reorderable_list 并实现它。正如您在它的演示中看到的那样,这个插件可以按照您想要的方式工作。
但是,它的工作方式与 ReorderableListView
完全不同,代码更改可能有点让人不知所措。我创建了一个小部件来简化该开关,即 widget is here and its demo is here.
看看它是否适合您的用例。
2021/05/29
作为答案的更新,已经有一个可自定义的处理程序 ReorderableListView
:
With the recent refactoring of the ReorderableListView (PRs: #74299 and #74697), we have added automatic drag handles when running on the desktop (with a buildDefaultDragHandles property to turn it off). If this isn't what you want, you can add your own drag handle as a widget to each of your items with something like:
ReorderableDragStartListener(
index: index,
child: const Icon(Icons.drag_handle),
),
您可以在这里查看详细信息:https://github.com/flutter/flutter/issues/46805