JS1
JS1

Reputation: 747

How to remove menu icons in flutter ReorderableListView

When I create a ReordableListView with flutter there are some Icons (in the right) that appear by default :

enter image description here

I would like to remove them because I want to put other Icons at this place and when I do this it renders this (which is obviously not what I want) :

enter image description here

Thanks for helping !

Upvotes: 0

Views: 3500

Answers (2)

Miftakhul Arzak
Miftakhul Arzak

Reputation: 1847

Set buildDefaultDragHandles to false and wrap your ListTile using ReorderableDragStartListener to set your item draggable.

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,
            child: 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);
        });
      },
    );
  }
}

Upvotes: 10

JS1
JS1

Reputation: 747

Found the answer, I just needed to add this line in my ReordableListView widget:

buildDefaultDragHandles: false,

Upvotes: 7

Related Questions