0

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 !

2 Answers 2

6

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

buildDefaultDragHandles: false,
1
  • 1
    It is not working. Because drag feature doesn' t work when remove this icon. Do you know any solution for that ? Dec 29, 2021 at 12:53
3

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);
        });
      },
    );
  }
}
1
  • I had to change ReorderableListView.Builder to ReorderableListView only and use childrens[] like in your example. Thanks for the tip ;) Sep 10 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.