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

drag_select_grid_view 封面
套件詳情v0.7.7

drag_select_grid_view

支援透過拖曳和點按來選擇項目之網格。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1520
喜歡數
171
Pub 分數
160

安裝套件

flutter pub add drag_select_grid_view

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供網格佈局,允許使用者透過點擊和拖曳手勢選擇項目。它透過支援跨多個網格方塊的連續選擇來增強使用者互動,非常適合需要批次操作或視覺內容編輯的應用程式。此套件支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,確保跨平台的一致性。該套件以效能與易用性為設計重點,可輕鬆整合至現有的 Flutter 專案中。

適用情境

  • 批量選擇照片畫廊中的項目
  • 互動式任務管理介面
  • 內容整理工具
  • 電商應用中的多選功能
  • 使用者驅動的資料過濾
  • 在生產力應用中拖曳選擇

主要特色

  • 支援點擊和拖曳選擇
  • 跨平台相容性
  • 可自定義的選擇行為
  • 大型資料集的高效渲染
  • 內建手勢處理
  • 與現有網格的輕鬆整合

適合對象

  • 開發互動式網格介面的開發者
  • 需要多項目選擇的應用程式
  • 針對多個平台的專案
  • 專注於直覺式使用者互動的設計師
  • 重視流暢手勢回應的團隊

使用建議

  • 可能需要額外的狀態管理來處理複雜的選取邏輯
  • 如果未優化,大型網格會帶來效能影響
  • 內建樣式選項有限,僅限基本選擇指示器
  • 不適用於僅單項選擇的使用情境

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

drag_select_grid_view

Pub package CI workflow Awesome

A grid that supports both dragging and tapping to select its items.

Selecting

Basic usage

DragSelectGridView constructor is very similar to GridView.builder, so you should take your time to understand the latter before diving into this library.

Once you are familiar with GridView.builder, probably the only additional piece of information you'll need is DragSelectGridViewController. With it, you're able to know which indexes are selected.

Check this example:

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final controller = DragSelectGridViewController();

  @override
  void initState() {
    super.initState();
    controller.addListener(scheduleRebuild);
  }

  @override
  void dispose() {
    controller.removeListener(scheduleRebuild);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: SelectionAppBar(
        selection: controller.value,
      ),
      body: DragSelectGridView(
        gridController: controller,
        itemCount: 20,
        itemBuilder: (context, index, selected) {
          return SelectableItem(
            index: index,
            selected: selected,
          );
        },
        gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
          maxCrossAxisExtent: 80,
        ),
      ),
    );
  }

  void scheduleRebuild() => setState(() {});
}

As you may have noticed in the code above, DragSelectGridView must be used along two other widgets in order to provide a proper user experience. In the example, they are:

  • SelectableItem: A selectable widget, which is going to visually indicate whether the item is selected or not.

  • SelectionAppBar: A custom AppBar, which shows the amount of selected items and an option to unselect them.

The example project provides some samples of those widgets. I won't add them to the library, since they are unrelated to the grid itself, but feel free to copy them into your project, as long as you respect the license terms.

Advanced usage

You can use the setter DragSelectGridViewController.value to directly change the selection (I'm not quite sure why you'd need this, but I don't ask questions).

It allows this sort of interaction:

Directly changing selection

You can check the code here.

There are some other minor settings you can do to make DragSelectGridView fit your needs, like DragSelectGridView.autoScrollHotspotHeight. Those features are well documented, so I'll let you take your discovery time.

Hopefully, this is everything you need to know to use this library.

Running the example

cd example
flutter create .
flutter run

Thanks ❤️

Once upon a time I asked at Flutter Study Group how to implement a specific feature that I intended to add to this library. Simon Lightfoot offered to help me and effortlessly implemented what eventually became part of this library (check this gist). A big thanks to him.

I took a lot of inspiration from Aidan Follestad's Android implementation, drag-select-recyclerview. Also a big thanks to him.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案