搜尋套件、儲存庫與 APP 分類

reorderable_grid_view 封面
套件詳情v2.2.8

reorderable_grid_view

可重新排序的網格視圖

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
5.9萬
喜歡數
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

所屬分類

原始碼儲存庫

使用此套件的專案