Flutter Sortable Drag And Drop ListView

flutter listview
flutter draggable
flutter listview transition
flutter listview order
listview builder flutter
flutter draggable scrollable sheet
flutter listview in column
flutter horizontal listview animation

So I'm starting to learn Flutter and would like to use a material design drag and drop list just like the one seen on the material guidelines website.

https://storage.googleapis.com/spec-host-backup/mio-design%2Fassets%2F1dtprsH4jZ2nOnjBCJeJXd7n4U-jmWyas%2F03-list-reorder.mp4

All of the libraries I have tried out so far look like garbage compared to that. Is there a good library for this that I am missing or a native Flutter widget?

Check knopp/flutter_reorderable_list. It accomplishes just that. It's really smooth and it's got no performance issues, being able to handle thousands of items.

However, it's implementation is not easy as usual flutter widgets.

If you struggle with that, I'd recommend you to use a widget I created to port flutter/ReorderableListViews to the knopp/ReorderableList.

This widget makes it really easy to use, however it doesn't provide the same flexibility, and as it works with a children List, it's not as scalable as the original.

Here's the code for ReorderableListSimple and this is the demo.

ReorderableListView (Flutter Widget of the Week), The ReorderableListView widget presents a list of items that users can reorder just by dragging Duration: 1:17 Posted: 17 Jul 2019 Flutter - Drag & Drop Listview - Reorderable Listview. Hello Guys, Today I am going to explain you about drag and drop items inside the listview. We will achieve this in flutter by ReorderableListView widget. ReorderableListview contains properties like childred, header, onReorder, scrollDirection

You can use native flutter widget, ReorderableListView to achieve it, here is the example of doing it.

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(() {});
      },
    ),
  );
}

Drag and drop to sort in Flutter, implement a drag and drop sortable functionality in flutter using only flutter SDK and core Duration: 2:41 Posted: 1 May 2020 Flutter Sortable Drag And Drop ListView, You can use native flutter widget, ReorderableListView to achieve it, here is the example of doing it.

I've tried flutter_reorderable_list and dragable_flutter_list but none of them worked properly - there was some unwanted artifacts during dragging. So I've tried to make own solution:

ListView.builder(
  itemBuilder: (context, index) => buildRow(index),
  itemCount: trackList.length,
),

Widget buildRow(int index) {
  final track = trackList[index];
  ListTile tile = ListTile(
    title: Text('${track.getName()}'),
  );
  Draggable draggable = LongPressDraggable<Track>(
    data: track,
    axis: Axis.vertical,
    maxSimultaneousDrags: 1,
    child: tile,
    childWhenDragging: Opacity(
      opacity: 0.5,
      child: tile,
    ),
    feedback: Material(
      child: ConstrainedBox(
        constraints:
            BoxConstraints(maxWidth: MediaQuery.of(context).size.width),
        child: tile,
      ),
      elevation: 4.0,
    ),
  );

  return DragTarget<Track>(
    onWillAccept: (track) {
      return trackList.indexOf(track) != index;
    },
    onAccept: (track) {
      setState(() {
        int currentIndex = trackList.indexOf(track);
        trackList.remove(track);
        trackList.insert(currentIndex > index ? index : index - 1, track);
      });
    },
    builder: (BuildContext context, List<Track> candidateData,
        List<dynamic> rejectedData) {
      return Column(
        children: <Widget>[
          AnimatedSize(
            duration: Duration(milliseconds: 100),
            vsync: this,
            child: candidateData.isEmpty
                ? Container()
                : Opacity(
                    opacity: 0.0,
                    child: tile,
                  ),
          ),
          Card(
            child: candidateData.isEmpty ? draggable : tile,
          )
        ],
      );
    },
  );
}

I guess, this is not the best solution, and I'm maybe will change it further, but for now it works quite well

Flutter Sortable Drag And Drop ListView, So I'm starting to learn Flutter and would like to use a material design drag and drop list just like the one seen on the material guidelines  Flutter - Drag & Drop Listview - Reorderable Listview. Hello Guys, Today I am going to explain you about drag and drop items inside the listview. We will achieve this in flutter by ReorderableListView widget. ReorderableListview contains properties like childred, header, onReorder, scrollDirection

Flutter itself provides a (Material) ReorderableListView class.

ReorderableListView class - material library - Dart API, ReorderableListView class. A list whose items the user can interactively reorder by dragging. This class is appropriate for views with a small number of children  ReorderableListView - Reorder ListView Items using Drag and Drop in Flutter This Article is posted by seven.srikanth at 23-08-2019 05:58:13 Click here to support us by Subscribing to our youtube channel.

Flutter team introduced ReorderableListView widget.

ReorderableListView(
      children: <Widget>[
        for (var item in appState.menuButtons) 
        Text('data')              

      ],
    )

reorderables, Various reorderable, a.k.a. drag and drop, Flutter widgets, including rows, whereas cells in a row of a list view don't align with other rows. sortable_listview. A new Flutter project. Getting Started. For help getting started with Flutter, view our online documentation.

Flutter Sortable Drag And Drop ListView, Flutter Sortable Drag And Drop ListView, You can use native flutter widget, ReorderableListView to achieve it, here is the example of doing it. I struggle to find any example of a Drag&Drop ListView, with the list items being a Row Widget made of at least two other Widgets and one of them inside an Expanded (I can see people having problems with the feedback Widget to keep the same dimension as the child of Draggable).

ListView Drag&Drop Example · Issue #13651 · flutter/flutter · GitHub, Luk3s changed the title Drag and drop list view ListView Drag&Drop isn't behaving exactly as I wanted but it did solve the sortable issue. Various reorderable, a.k.a. drag and drop, Flutter widgets, including reorderable table, row, column, wrap, and sliver list, that make their children draggable and reorder them within the widget. Parent widget only need to provide an onReorder function that is invoked with the old and new indexes of child being reordered.

drag_list, drag_list | Flutter list widget that allows to drag and drop items as well as define custom drag New comments cannot be posted and votes cannot be cast. Sort by. best Just FYI there is a ReorderableListView class in flutter which is similar. Flutter Sortable Drag And Drop ListView, You can use native flutter widget, ReorderableListView to achieve it, here is the example of doing it. May 26, 2018 · Scrollable widgets, including ListView, GridView, PageView. Builder pattern must be used because of its infinite nature.

Comments
  • Your version worked great, thanks. I would like it to be a little less laggy though when reordering every tile. Don't know if it will be smoother in the release version. Also, I can't figure out how to customize / remove the vibrations when reordering.
  • I also just ran into the issue where when I make the list tile dismissable (flutter.io/docs/cookbook/gestures/dismissible) the handle doesn't move while the rest of it slides away as it should.
  • I know it's not a solution, but in my app, after some fighting, I decided to use a reordering mode. :( So in reordering mode I use the ReorderingList and there's a handle (and you can't do anything else), and when it's not reordering then the user can do all the rest.
  • If you are using the ReorderingListSimple, maybe you could use childrenAlreadyHaveListener = true, then place the ReorderableListener manually in to the ListTile and make it disappear on Dismissible``s onRezize`! Let me know if it works!! I know that's not great, but maybe it's valid temporary solution.
  • Long press to reorder
  • Just a detail, as I understand it you should avoid empty setState calls and it seems to me as all the code in onReorder could just as well be inside the setState call?
  • Do note, the long press to reorder is absolutely breaking the material design spec and should not be used on Android (no idea about iOS). As far as I have been able to figure out so far there is no way to provide handles which can be simply grabbed with ReorderableListView
  • @DavidMulder That's how Flutter implemented it, you can file a bug on Github mentioning the issue.
  • @CopsOnRoad Was going to do that, but then noticed there are 5000 open issues on the Flutter Github and realized that 1) it would be pointless to post there and 2) that I will definitely not be doing any production work with flutter 😅 . So yeah, just wanted to leave that as an aside here as it's a pretty important thing to realize and it's not that obvious from the image you included.
  • It seems that I've done a little useless work ))) Anyway, it was interesting experience. It's a pity that `ReorderableListView' doesn't use builder, but I think I'll use it for my needs. Thanks