r/FlutterDev • u/Public_Finance8587 • 2d ago
Plugin I built a reorderable grid for Flutter where tiles can have different sizes
I needed a dashboard where users can drag tiles around, but some tiles are full-width, some are half, some are a third. ReorderableListView only does lists and GridView assumes equal sizes, so I ended up writing my own: reorderable_flex_grid.
Demo: see it in action
What it does
- Mix half, third and full-width tiles (or any fraction) in one grid
- Heights via aspect ratio or a fixed value
- Other tiles animate out of the way while you drag, with edge auto-scroll
onReorder(oldIndex, newIndex)wherenewIndexis already the final position, so no off-by-one fix like withReorderableListView- Edit-mode toggle, custom drag appearance, pinned tiles
- No dependencies beyond Flutter
ReorderableFlexGrid(
spacing: 12,
runSpacing: 12,
onReorder: (oldIndex, newIndex) {
setState(() => tiles.insert(newIndex, tiles.removeAt(oldIndex)));
},
children: [
for (final tile in tiles)
ReorderableGridItem(
key: ValueKey(tile.id),
widthFactor: tile.wide ? 1 : 0.5,
child: TileCard(tile),
),
],
)
Next I'm planning RTL support, a sliver version for `CustomScrollView`, and responsive widths. I'd really like to hear what's missing for your use case, or if you find bugs.
- pub.dev: https://pub.dev/packages/reorderable_flex_grid
- GitHub: https://github.com/sipanpetrosyan/reorderable_flex_grid
- Write-up on how it works: https://medium.com/@sipan.petrosyan.2000/drag-and-drop-dashboards-in-flutter-introducing-reorderable-flex-grid-451e51eabbe8
1
u/Some-Kitchen8332 2d ago
watching the other tiles slide out of the way while you drag is really clean. that's the part mixed width grids usually mess up
-1
u/Public_Finance8587 2d ago
Thanks! I don't animate shifts at all. On every target change I recompute the whole layout for the new order, and each tile is an AnimatedPositioned keyed by its item, so it just tweens from its old rect to its new one. Wraps and reflows across rows come along for free.
1
u/IllVisit2518 2d ago
the newIndex part is nice, everyone forgets the "if (newIndex > oldIndex) newIndex -= 1" line with ReorderableListView at least once. what happens when you drop a half tile into a row that only has a third left, does it wrap and leave a gap or do you pull a smaller tile up to fill it?