Skip to main content

reorderable_flex_grid 0.1.0 copy "reorderable_flex_grid: ^0.1.0" to clipboard
reorderable_flex_grid: ^0.1.0 copied to clipboard

A Flutter grid whose tiles can have different widths and heights (half, third, full row, ...) and can be reordered with drag and drop.

reorderable_flex_grid #

A Flutter grid whose tiles can have different widths and heights and can be reordered by drag and drop. Use it for dashboards, home screens and settings pages where some tiles span the whole row and others share it.

  • Mix half-, third- and full-width tiles, or any fraction in between.
  • Each tile sets its height through an aspect ratio or a fixed height.
  • Other tiles animate out of the way while you drag, and the dropped tile settles into its slot.
  • The grid scrolls when you drag near its top or bottom edge.
  • It's sized by its own constraints, not the screen, so it works inside padding, split views and side panels.
  • No dependencies beyond Flutter.

Getting started #

dependencies:
  reorderable_flex_grid: ^0.1.0

Usage #

The grid doesn't store the order itself. It calls onReorder, and you rebuild it with the children in the new order, the same way ReorderableListView works.

import 'package:reorderable_flex_grid/reorderable_flex_grid.dart';

class Dashboard extends StatefulWidget {
  const Dashboard({super.key});

  @override
  State<Dashboard> createState() => _DashboardState();
}

class _DashboardState extends State<Dashboard> {
  final tiles = ['Revenue', 'Orders', 'Visitors', 'Activity'];

  @override
  Widget build(BuildContext context) {
    return ReorderableFlexGrid(
      padding: const EdgeInsets.all(12),
      spacing: 12,
      runSpacing: 12,
      onReorder: (oldIndex, newIndex) {
        setState(() => tiles.insert(newIndex, tiles.removeAt(oldIndex)));
      },
      children: [
        for (final tile in tiles)
          ReorderableGridItem(
            key: ValueKey(tile), // required, unique among the items
            widthFactor: tile == 'Revenue' ? 1 : 0.5,
            aspectRatio: tile == 'Revenue' ? 2 : 1,
            child: Card(child: Center(child: Text(tile))),
          ),
      ],
    );
  }
}

newIndex is the item's index in the reordered list, so list.insert(newIndex, list.removeAt(oldIndex)) is all you need. You don't have to adjust the index as you do with ReorderableListView.

Item sizing #

ReorderableGridItem Meaning
widthFactor Fraction of the row the tile takes, in (0, 1]. Defaults to 0.5.
aspectRatio Width ÷ height, as in Flutter's AspectRatio. Defaults to 1.
height Fixed height. Overrides aspectRatio.
draggable Set to false to pin a tile. Other tiles can still move around it.

Tiles flow left to right and wrap when the next tile doesn't fit in the row. A row is as tall as its tallest tile.

Grid options #

ReorderableFlexGrid Meaning
spacing / runSpacing Gaps between tiles in a row and between rows.
padding, controller, physics Passed to the underlying scroll view.
enabled Turn dragging off, for example outside an "edit" mode.
longPressToDrag true (default) needs a long press; false starts dragging immediately, which suits mouse input.
onReorderStart / onReorderEnd Hooks for haptics or UI changes.
proxyDecorator Customize how the lifted tile looks.
animationDuration / animationCurve Reflow and drop animation.
autoScrollEdgeExtent / autoScrollVelocityScalar Edge auto-scroll tuning.

Custom drag appearance #

ReorderableFlexGrid(
  proxyDecorator: (child, index, animation) => AnimatedBuilder(
    animation: animation,
    builder: (context, child) => Material(
      elevation: 8 * animation.value,
      borderRadius: BorderRadius.circular(12),
      child: child,
    ),
    child: child,
  ),
  // ...
)

Notes #

  • Every tile is built up front, so the grid suits a moderate number of tiles (dozens), not thousands.
  • The grid creates its own vertical scroll view. Give it bounded height, for example with Expanded or as a Scaffold body.

See example/ for a complete dashboard with an edit-mode toggle.

3
likes
0
points
67
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter grid whose tiles can have different widths and heights (half, third, full row, ...) and can be reordered with drag and drop.

Repository (GitHub)
View/report issues

Topics

#grid #reorderable #drag-and-drop #dashboard

License

unknown (license)

Dependencies

flutter

More

Packages that depend on reorderable_flex_grid