如何在 flutter ReorderableListView 中删除菜单图标

How to remove menu icons in flutter ReorderableListView

当我用 flutter 创建一个 ReordableListView 时,默认情况下会出现一些图标(在右边):

我想删除它们,因为我想把其他图标放在这个地方,当我这样做时它会呈现这个(这显然不是我想要的):

感谢您的帮助!

找到答案,我只需要在我的 ReordableListView 小部件中添加这一行:

buildDefaultDragHandles: false,

buildDefaultDragHandles 设置为 false 并使用 ReorderableDragStartListener 包装您的 ListTile 以将您的项目设置为可拖动。

class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  final List<int> _items = List<int>.generate(50, (int index) => index);

  @override
  Widget build(BuildContext context) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;
    final Color oddItemColor = colorScheme.primary.withOpacity(0.05);
    final Color evenItemColor = colorScheme.primary.withOpacity(0.15);

    return ReorderableListView(
      padding: const EdgeInsets.symmetric(horizontal: 40),
      // Set this false
      buildDefaultDragHandles: false,
      children: <Widget>[
        for (int index = 0; index < _items.length; index++)
          // Wrap using ReorderableDragStartListener
          ReorderableDragStartListener(
            key: Key('$index'),
            index: index,
            ListTile(
              tileColor: _items[index].isOdd ? oddItemColor : evenItemColor,
              title: Text('Item ${_items[index]}'),
            )
          ),
      ],
      onReorder: (int oldIndex, int newIndex) {
        setState(() {
          if (oldIndex < newIndex) {
            newIndex -= 1;
          }
          final int item = _items.removeAt(oldIndex);
          _items.insert(newIndex, item);
        });
      },
    );
  }
}