1

The following example code is taken from here

List<String> _list = ["Apple", "Ball", "Cat", "Dog", "Elephant"];

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(),
    body: ReorderableListView(
      children: _list.map((item) => ListTile(key: Key("${item}"), title: Text("${item}"), trailing: Icon(Icons.menu),)).toList(),
      onReorder: (int start, int current) {
        // dragging from top to bottom
        if (start < current) {
          int end = current - 1;
          String startItem = _list[start];
          int i = 0;
          int local = start;
          do {
            _list[local] = _list[++local];
            i++;
          } while (i < end - start);
          _list[end] = startItem;
        }
        // dragging from bottom to top
        else if (start > current) {
          String startItem = _list[start];
          for (int i = start; i > current; i--) {
            _list[i] = _list[i - 1];
          }
          _list[current] = startItem;
        }
        setState(() {});
      },
    ),
  );
}

I am using Flutter's native ReorderableListView widget but I would like to separate my list into 3 expandable categories; each category has its own header/ExpansionTile which can't be dragged like the other ListTiles.

Is there a way to do this using only native Flutter widgets?

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Landon
  • 528
  • 2
  • 4
  • 22
  • I believe you have upvoted my answer ;) Can you show a screenshot/video of what exactly you are trying to achieve? – CopsOnRoad Aug 12 '19 at 04:10
  • https://therubberduckdev.files.wordpress.com/2017/10/recyclerview-manual-drag-drop.gif?w=1100 – Landon Aug 12 '19 at 12:32

0 Answers0