Flutter Reordering Made Easy with reorderable_wrap
Résumé
Pixel’s announcement introduces reorderable_wrap, a dependency-free Flutter package for drag-to-reorder Wraps, lazy grids, tables, rows, and columns. It highlights consistent index behavior, flexible drag controls, animated movement, and nested-scroll auto-scrolling—useful capabilities for layouts beyond Flutter’s single-column ReorderableListView.
DEV Community
reorderable_wrap: drag-to-reorder Wrap, grid, table, Row and Column in Flutter
Flutter ships a good widget for reordering: ReorderableListView. It does one thing, a single-column scrolling list, and does it well. The trouble is that many things users want to drag around are not single-column lists. Tags that flow over several lines. A grid of photos. Table rows whose cells must stay lined up with the columns. A short row of steps inside a form. For those, the usual package was reorderables. Its last release, 0.6.0, dates from January 2023, and its SDK constraint excludes Dart 3. reorderable_wrap provides the drag-to-reorder layouts that Flutter does not ship: a multi-line Wrap, a lazy grid, a Table, and non-scrolling Row and Column. It has no dependencies, and all the widgets behave the same way. What it does Five layouts. ReorderableWrap reorders children of a Wrap, with multi-line flow, spacing, runSpacing, every alignment option, and children of different sizes. ReorderableGridView.builder and SliverReorderableGrid give a lazily built grid from an itemBuilder, for large collections. ReorderableTable reorders rows while cells stay aligned to the columns, with an optional fixed header row. ReorderableRow and ReorderableColumn are non-scrolling, for small sets. Expanded and Flexible children keep flexing. One index convention everywhere. newIndex is the index after the move. More on that below, because it removes a classic bug. Drag control. A drag starts by long press (the default), immediately, or only from a ReorderableHandle. There are callbacks for onReorder, onReorderStart, onReorderEnd and onNoReorder, and buildDraggableFeedback to decorate the item that follows the pointer. Motion. The other items are displaced with an animation, and the drop is animated too. Auto-scroll. Dragging near an edge scrolls any enclosing Scrollable, including nested scroll views: the inner view scrolls first, then the outer one. The details. Optional haptic feedback, a per-item enabled flag, a whole-widget enabled switch, and RTL. Accessibility. Every item gets the "Move to the start", "Move up/left", "Move down/right" and "Move to the end" custom semantics actions, the same pattern and localized labels as ReorderableListView. State is kept. Children keep their State while dragged and after they move. Keys are required and checked: a missing or duplicate key fails with a clear error. How to use it Add it from GitHub: dependencies:
reorderable_wrap:
git: https://github.com/AbdeldjalilChougui/reorderable_wrap
The index convention onReorder(oldIndex, newIndex) gives the index the item will have after the move. Applying it is always one line, for every widget in the package: items.insert(newIndex, items.removeAt(oldIndex));
Compare that with ReorderableListView, which counts newIndex before removal, so moving an item down needs if (newIndex > oldIndex) newIndex -= 1;. Here no adjustment is needed. Wrap ReorderableWrap(
spacing: 8,
runSpacing: 8,
onReorder: (oldIndex, newIndex) => setState(
() => tags.insert(newIndex, tags.removeAt(oldIndex)),
),
children: [
for (final tag in tags) Chip(key: ValueKey(tag), label: Text(tag)),
],
)
Grid ReorderableGridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
),
itemCount: photos.length,
itemBuilder: (context, index) => Card(
key: ValueKey(photos[index].id),
child: Image.network(photos[index].url, fit: BoxFit.cover),
),
onReorder: (oldIndex, newIndex) => setState(
() => photos.insert(newIndex, photos.removeAt(oldIndex)),
),
)
Inside a CustomScrollView, use SliverReorderableGrid with the same arguments. Table ReorderableTable(
header: const [Text('Item'), Text('Qty')],
columnWidths: const {0: FlexColumnWidth(2), 1: FlexColumnWidth()},
onReorder: (oldIndex, newIndex) => setState(
() => rows.insert(newIndex, rows.removeAt(oldIndex)),
),
children: [
for (final row in rows)
ReorderableTableRow(
key: ValueKey(row.id),
children: [Text(row.name)...

Powered by Readybot.io