搜索插件、代码仓与 APP 分类

reorderable_grid_view 封面
插件详情v2.2.8

reorderable_grid_view

可重新排序的网格视图

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
5.4万
喜欢数
164
Pub 分数
120

安装插件

flutter pub add reorderable_grid_view

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可实现网格布局中项目的拖拽排序。它扩展了 GridView 的功能,允许用户通过手势直观地重新排列瓷砖。非常适合自定义仪表板、任务看板或任何需要动态项目定位的 UI。该包支持所有主要平台,包括移动设备、网页和桌面端,确保在不同设备上行为一致。专为性能和易于集成而设计,可在现有 Flutter 应用中无缝使用。

适合场景

  • 可自定义的仪表板布局
  • 任务管理界面
  • 照片画廊重新排列
  • 基于用户偏好的项目排序
  • 基于网格的交互式设置

主要特点

  • 拖拽重排
  • 跨平台兼容性
  • 与现有 GridView 的简单集成
  • 支持自定义拖动手柄
  • 内置动画,实现流畅过渡

适合对象

  • 开发交互式网格 UI 的开发者
  • 需要用户驱动内容排列的应用程序
  • 具有动态布局需求的项目

使用建议

  • 需要仔细处理状态管理
  • 在非常大的数据集上可能会影响性能
  • 拖拽反馈的自定义选项有限
  • 未针对极高频率的更新进行优化

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

ReorderableGridView

Idea from official ReorderableListView

Usage:

dependencies:
  reorderable_grid_view: ^2.2.9-alpha.4

Example

Sceenshot
class _MyHomePageState extends State<MyHomePage> {
  final data = [1, 2, 3, 4, 5];

  @override
  Widget build(BuildContext context) {
    Widget buildItem(String text) {
      return Card(
        key: ValueKey(text),
        child: Text(text),
      );
    }

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),

      body: Center(
        // use ReorderableGridView.count() when version >= 2.0.0
        // else use ReorderableGridView()
        child: ReorderableGridView.count(
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
          crossAxisCount: 3,
          children: this.data.map((e) => buildItem("$e")).toList(),
          onReorder: (oldIndex, newIndex) {
            setState(() {
              final element = data.removeAt(oldIndex);
              data.insert(newIndex, element);
            });
          },
          footer: [
            Card(
              child: Center(
                child: Icon(Icons.add),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Options

option desc
dragWidgetBuilderV2 the drag widget builder
restrictDragScope restrict drag scope to ReorderableGridView, not drag over the scree, default is false
dragStartDelay the longPress time
scrollDirection the scroll direction, default is Axis.vertical, supports Axis.horizontal
scrollSpeedController control how speed when scroll down when drag out of viewport
OnDropIndexChange the drop position changed, void (index, oldIndex), oldIndex = nil if is drag start.

dragWidgetBuilderV2

Normaly you can do like this:

dragWidgetBuilderV2: DragWidgetBuilderV2(
	isScreenshotDragWidget: false,
	builder: (index, child, screenshot) {
		return child;
	}
)
  • child is you dragging widget.

And if you dragging widget has some state, the callback's child can't access the state. So you can do a screenshot like this.

dragWidgetBuilderV2: DragWidgetBuilderV2(
	isScreenshotDragWidget: true,
	builder: (index, child, screenshot) {
		return Image(screenshot);
	}
)

Constructors

  • ReorderableGridView.builder
  • ReorderableGridView.count
  • ReorderableSliverGridView.count

custom reorderable

You can use ReorderableWrapperWidget to custom your reorderable. Use ReorderableWrapperWidget as root. and it's descendants is ReorderableItemView[] list

  • ReorderableWrapperWidget(child: SomeCollection(children: ReorderableItemView))

Important

  • the placeholderBuilder is not right when the list is very long, is not fixable for now. please see issue 47
  • can drag out of scope in ReorderableSliverGridView, please see issue 52

TODO

fix placeholderBuilder is not right when the list is very long

Other link project

If this project is not fit your meet, you can try those other projects

所属分类

源码仓库

使用此插件的项目