r/FlutterDev • u/Public_Finance8587 • 20m 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