A Flutter inplementation of the reorderable grid UI pattern, closely mimics Flutters exisiting ReorderableList

Overview

🔳 Reorderable Grid

Pub Version Likes Pub points Pub codecov

A full reorderable grid implemention similar to Flutters Reorderable_List. with full ReorderableGridView, ReorderableGrid and SliverReorderableGrid implementations

gif showing basic usage

🔨 How it works

ReorderableGridView is a drop in replacement for the existing GridView and adds an onReorder callback that provides the original and new index of the reordered item.

/// create a new list of data
final items = List<int>.generate(40, (index) => index);

/// when the reorder completes remove the list entry from its old position
/// and insert it at its new index
void _onReorder(int oldIndex, int newIndex) {
setState(() {
    final item = items.removeAt(oldIndex);
    items.insert(newIndex, item);
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
    home: Scaffold(
      body: ReorderableGridView.extent(
        maxCrossAxisExtent: 250,
        onReorder: _onReorder,
        childAspectRatio: 1,
        children: items.map((item) {
          /// map every list entry to a widget and assure every child has a 
          /// unique key
          return Card(
            key: ValueKey(item),
            child: Center(
            child: Text(item.toString()),
            ),
          );
        }).toList(),
      ),
    ),
);
}

ReorderableGrid provides all the constructors and parameters the normal GridView has. The package also includes:

  • ReorderableGridView, which is a prebuild Material-ish implementation of the grid.
  • ReorderableGrid, A barebones widget that allows you to customize the grid however you want
  • SliverReorderableGrid, a reorderable grid sliver for custom scroll implementations

👋 Get Involved

If this package is useful to you please 👍 on pub.dev and on github. If you have any Issues, recommendations or pull requests I'd love to see them!

Comments
  • disable autoscroll

    disable autoscroll

    This PR automatically disables autoscrolling if physics are NeverScrollableScrollPhysics. It also allows the developer to override this automatic behavior using the autoScroll argument on ReorderableGrid, SliverReorderableGrid, and ReorderableGridView

    Issues

    Resolves https://github.com/casvanluijtelaar/reorderable_grid/issues/10

    Code

    return ReorderableGrid(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: widget.layout.crossAxisCount,
        childAspectRatio: widget.layout.childAspect,
        mainAxisSpacing: widget.layout.gap,
        crossAxisSpacing: widget.layout.gap,
      ),
      itemCount: 9,
      physics: const NeverScrollableScrollPhysics(), ///////////////////////
      itemBuilder: (context, i) {
        return ReorderableGridDragStartListener(
          key: ValueKey(i),
          index: i,
          child: Container(
            color: Colors.red,
            child: Text(i.toString()),
          ),
        );
      },
      onReorder: (i, j) {
        print('from $i to $j');
      },
    );
    

    Before

    https://user-images.githubusercontent.com/666539/172380122-a644ae1d-fda1-426f-8040-5c8e7a591591.mov

    After

    https://user-images.githubusercontent.com/666539/172380210-e59b1d5b-7c03-4c71-9639-b2b396e6a97b.mov

    opened by lukepighetti 3
  • Auto-scroll does not respect reverse:true

    Auto-scroll does not respect reverse:true

    It looks like auto-scroll on extents does not respect reverse: true

    https://user-images.githubusercontent.com/666539/172375755-5603af1f-55d6-4d1c-ba27-40884ddbb5df.mov

    bug 
    opened by lukepighetti 2
  • Error: Assertion failed: isValid is not true

    Error: Assertion failed: isValid is not true

    I keep getting this.

    Exception has occurred. "Error: Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/engine/engine/html/path/path_ref.dart:898:12 isValid is not true at Object.throw [as throw] (http://localhost:42043/dart_sdk.js:5067:11) at Object.assertFailed (http://localhost:42043/dart_sdk.js:4992:15) at _engine.PathRef.shiftedFrom.debugValidate (http://localhost:42043/dart_sdk.js:161437:31) at new _engine.PathRef.shiftedFrom (http://localhost:42043/dart_sdk.js:161574:10) at new _engine.SurfacePath.shiftedFrom (http://localhost:42043/dart_sdk.js:159586:21)

    image

    help wanted question 
    opened by sgehrman 2
  • fix autoscrolling for non standard orientations

    fix autoscrolling for non standard orientations

    fixes https://github.com/casvanluijtelaar/reorderable_grid/issues/9

    • [x] fix auto scroll for different Direction
    • [x] fix auto scroll for reverse scroll
    opened by casvanluijtelaar 1
  • How to use SliverReorderableGrid?

    How to use SliverReorderableGrid?

    Regarding the use of SliverReorderableGrid, can you provide a code demo? I have a problem when I use it, I can’t drag, the code is as follows

    import 'package:flutter/material.dart';
    import 'package:reorderable_grid/reorderable_grid.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatefulWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      _MyAppState createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      final items = List<int>.generate(40, (index) => index);
    
      void _onReorder(int oldIndex, int newIndex) {
        setState(() {
          final item = items.removeAt(oldIndex);
          items.insert(newIndex, item);
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
              body: CustomScrollView(
            slivers: [
              SliverReorderableGrid(
                  itemCount: items.length,
                  itemBuilder: (context, index) => Card(
                        key: ValueKey(index),
                        child: Center(
                          child: Text(index.toString()),
                        ),
                      ),
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 3,
                    childAspectRatio: 3 / 5,
                    mainAxisSpacing: 10.0,
                    crossAxisSpacing: 10.0,
                  ),
                  onReorder: _onReorder)
            ],
          )),
        );
      }
    }
    
    question 
    opened by anjinwang 1
  • Automatically animate on list update.

    Automatically animate on list update.

    It would be really nice if the drag/drop animation could be triggered when the list gets updated, not only with a long press and dragging and dropping an item.

    For example:

    Original list: [1, 2, 3, 4, 5, 6]

    Grid:
    [1, 2, 3]
    [4, 5, 6]
    

    List updated: [1, 2, 4, 5, 6] (item 3 removed in the backend)

    Grid:
    [1, 2, 4]
    [5, 6]
    

    The list gets updated just fine, but without any animation. I'll look at your code to see how can we implement this.

    enhancement question 
    opened by renannery 1
  • Support reordering with animation for programatic changes to the data source

    Support reordering with animation for programatic changes to the data source

    In my app, I don't need the user to reorder the contents but they are done when some filters are enabled.

    Use case:

    • Grids show cars.
    • When user presses red color, I want to show only the red colored cars
    • And I want this filtering to happen in an animated way.
    • So there might be several cars that are removed from different places of the cars array.
    • When the filter is removed, all cars should be added in place with ordering animation.

    Can I use this package for this need?

    This implicitly_animated_reorderable_list package does it using a diff algorithm

    enhancement question 
    opened by aytunch 1
  • No way to disable auto-scroll

    No way to disable auto-scroll

    I am using this package in a fixed grid scenario, where NeverScrollablePhysics is being used. However, auto-scroll still appears to be active when it's expected to never scroll.

    https://user-images.githubusercontent.com/666539/172376349-21e4e2d6-d763-4e0b-89ec-77752c2675cd.mov

    return ReorderableGrid(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: widget.layout.crossAxisCount,
        childAspectRatio: widget.layout.childAspect,
        mainAxisSpacing: widget.layout.gap,
        crossAxisSpacing: widget.layout.gap,
      ),
      itemCount: 9,
      physics: const NeverScrollableScrollPhysics(),
      reverse: false,
      itemBuilder: (context, i) {
        return ReorderableGridDragStartListener(
          key: ValueKey(i),
          index: i,
          child: Container(
            color: Colors.red,
            child: Text(i.toString()),
          ),
        );
      },
      onReorder: (i, j) {
        print('from $i to $j');
      },
    );
    
    bug 
    opened by lukepighetti 0
  • ReorderableGridView with shrinkWrap expands vertically when reordering, if last row is 'full'

    ReorderableGridView with shrinkWrap expands vertically when reordering, if last row is 'full'

    If a ReorderableGridView.extent has shrinkWrap set to true, and the last row is full of items, then an extra row is added to the grid view when reordering is started:

    https://user-images.githubusercontent.com/66305960/174491136-a38d9a64-c3f5-40b2-84e0-0ff4b691c49e.mp4

    This does not happen if the last row is not full. I would expect it not to happen in general.

    Thanks again!

    import 'package:flutter/material.dart';
    import 'package:reorderable_grid/reorderable_grid.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatefulWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      _MyAppState createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      final items = List<int>.generate(3, (index) => index);
    
      void _onReorder(int oldIndex, int newIndex) {
        setState(() {
          final item = items.removeAt(oldIndex);
          items.insert(newIndex, item);
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            body: Column(
              children: [
                Container(
                  color: Colors.blue,
                  child: ReorderableGridView.extent(
                    shrinkWrap: true,
                    maxCrossAxisExtent: 250,
                    onReorder: _onReorder,
                    childAspectRatio: 1,
                    children: items.map((item) {
                      return Card(
                        key: ValueKey(item),
                        child: Center(
                          child: Text(item.toString()),
                        ),
                      );
                    }).toList(),
                  ),
                ),
                const Text("Below"),
              ],
            ),
          ),
        );
      }
    }
    
    
    enhancement help wanted 
    opened by olof-dev 2
  • Cannot drop item back in its original position

    Cannot drop item back in its original position

    It appears to be impossible to drop an item back in its original position, at least in the package's sample app (and in my app where I tried to use this package). The items to the left and right of the item that's being dragged are 'glued' together:

    https://user-images.githubusercontent.com/66305960/174432363-7a1d28e6-3f9c-43f6-ad96-f586a595ffd8.mp4

    This doesn't seem to be an issue in https://github.com/huhuang03/reorderable_grid_view/, which I gather this package started from. (That package lacks some things that this one has, however.)

    Thanks for this package!

    bug 
    opened by olof-dev 2
  • Can reorder to the right, but not to the left

    Can reorder to the right, but not to the left

    It's very easy to reorder by dragging items to the right, but much more difficult to reorder by dragging to the left.

    It looks like the breakpoint is the leading edge (LTR) of each item, instead of the bounds of each item.

    https://user-images.githubusercontent.com/666539/172383219-1fdf5bc8-fd3a-4675-80cc-8b364233ef39.mov

    bug 
    opened by lukepighetti 0
Releases(v1.0.1)
This is a Flutter app which shows how to use the Reorderable List View in your app

reorderable_list_view A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

Shehzaan Mansuri 1 Oct 25, 2021
Reorderable list for flutter.

Reorderable List in Flutter iOS-like proof of concept reorderable list with animations Preview Getting Started See example/lib/main.dart for example u

null 0 Dec 25, 2021
Reorderable list for flutter.

Reorderable List in Flutter iOS-like proof of concept reorderable list with animations Preview Getting Started See example/lib/main.dart for example u

null 1 Apr 13, 2022
A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

WhatTodo Life can feel overwhelming. But it doesn’t have to. A Simple To-do app design in flutter to keep track of your task on daily basis. You can a

Burhanuddin Rashid 1k Jan 6, 2023
Minimalist Flutter Todo App, built using BLoC pattern

Deer Minimalist Todo Planner app built around the idea of efficiency and clean aesthetic. Showcase Development Deer uses BLoC (Business Logic Componen

Aleksander Woźniak 355 Dec 24, 2022
Implementing Firebase Authentication with Riverpod following Flutter Domain Driven Development pattern

firebase_auth_flutter_ddd Firebase authentication example with Hooks Riverpod and Freezed following Flutter DDD architecture Getting Started This proj

Python Hub 42 Jan 8, 2023
flutter project using Bloc Pattern

bloc_project A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

WendellClaus 0 Nov 15, 2022
simple Demo bloc Pattern in StateManagment in flutter

Weather Fake App A new Flutter application. Getting Started This project is a starting point for a Bloc Pattern in Flutter. This Simple Demo for bloc

Essam Mohamed 1 Oct 12, 2021
Caching with flutter riverpod and looking into future providers. Example to demonstrate stale while revalidate pattern.

FLUTTER SWR EXAMPLE Test stale-while-revalidate pattern with riverpod. Look; query_provider package Backend calls are made with ghibli-api Tested Prov

Dipesh Dulal 7 Jun 30, 2022
Sorting Visualizer using Flutter followed MVVM Pattern and used Stacked Services. Hope you like it 😋

Sortlizer An App to visualize various sorting algorithms...Developed using Flutter, followed MVVM pattern, and used stacked services. Play Store Link

Roshan Kumar 17 Dec 28, 2022
A mobile medicine reminder built with Flutter, Provider and BLoC pattern.

Mediminder An Offline Medicine Reminder Built with Flutter, Provider and BLoC pattern Key Features Homepage medicine list Homepage containing all the

null 231 Jan 3, 2023
Fluttermobile - Flutter Movie App Using BLoc Pattern and JSON API

Flutter Movie App Using BLoc Pattern and JSON API. Data Provider: https://www.th

BEŞİR ÖZTEN 5 Jul 6, 2022
A basic implementation of the robot testing pattern for integration/e2e tests

robot A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is

Samuel Abada 3 Dec 13, 2021
Flutter Music Player - First Open Source Flutter based material design music player with audio plugin to play local music files.

Flutter Music Player First Open Source Flutter based Beautiful Material Design Music Player(Online Radio will be added soon.) Demo App Play Store BETA

Pawan Kumar 1.5k Jan 8, 2023
a project for learning all Flutter Widgets , sync from flutter.dev the officia website.

Flutter Widgets Catalog (WIP) 计划 1、使用Flutter开发一个全平台的Flutter Widgets Catalog APP,并且开源。在这个APP中可以通过图形化的方式查看所有Widgets的介绍,示例,视频教程。 2、所有文档内容由前一天从flutter.dev

ezshine 32 Aug 3, 2022
A low-cost Flutter screen adaptation solution(一个极低成本的 Flutter 屏幕适配方案)

A low-cost Flutter screen adaptation solution(一个极低成本的 Flutter 屏幕适配方案) 100% 还原 UI,只需要按照设计图写的宽高写即可 先看图片,设置的标准宽度是 360 iPhone 8 --------------------------

聂志洋 108 Sep 27, 2022
A Flutter package that makes it easy to customize and work with your Flutter desktop app's system tray.

system_tray A Flutter package that that enables support for system tray menu for desktop flutter apps. on Windows, macOS and Linux. Features: - Modify

AnTler 140 Dec 30, 2022
Email and Password Authentication In Flutter & Firebase in Flutter 2.2

Email and Password Authentication In Flutter & Firebase in Flutter 2.2

BackSlash Flutter 43 Nov 23, 2022