パッケージ、リポジトリ、アプリカテゴリを検索

flutter_reorderable_grid_view のカバー
パッケージ詳細v5.8.0

flutter_reorderable_grid_view

子要素を更新するときや、ドラッグアンドドロップで並べ替えようとするときに、アニメーション付きのGridViewを有効にします。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
4.2万
いいね数
255
Pub ポイント
160

パッケージをインストール

flutter pub add flutter_reorderable_grid_view

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

GridView 内のアイテムをアニメーション付きでドラッグアンドドロップで再配置できるFlutterパッケージです。タイルの再配置やグリッドの子要素の更新時にスムーズな遷移を提供し、グリッドベースのレイアウトにおけるユーザーインタラクションを向上させます。ダッシュボード、写真ギャラリー、カスタマイズ可能なインターフェースなど、動的でインタラクティブなグリッドが必要なアプリに最適です。このパッケージはモバイル、Web、デスクトップを含むすべての主要プラットフォームをサポートしています。

用途

  • インタラクティブなダッシュボードレイアウト
  • 写真またはメディアギャラリーの並べ替え
  • カスタマイズ可能な UI グリッド
  • ドラッグアンドドロップによるタスク管理
  • 動的コンテンツの再配置

主な機能

  • アニメーション付きドラッグアンドドロップによる再順序付け
  • 再配置時のスムーズな遷移
  • すべての Flutter プラットフォームをサポートしています
  • 既存の GridView との簡単な統合
  • 動的子要素の更新を処理する

適している対象

  • インタラクティブなグリッドインターフェースを構築する開発者
  • ユーザー主導のコンテンツ配置を必要とするアプリ
  • クロスプラットフォームグリッドアプリケーション
  • 頻繁なレイアウト変更のある UI

注意事項

  • 非常に大きなデータセットではパフォーマンスが低下する可能性があります
  • アイテムキーの取り扱いに注意が必要です
  • 非常に高い頻度の更新には最適化されていません
  • 基本的なドラッグ動作以外のカスタマイズが限られている

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Pub Version GitHub branch checks state

An animated image of the iOS ReordableGridView UI An animated image of the iOS ReordableGridView UI

Package for having animated Drag and Drop functionality for every type of GridView and to have animations when changing the size of children inside your GridView.

Index

Overview

Enhance your Flutter app with this package to:

  • Enable animated drag-and-drop functionality:
    • Works seamlessly with any GridView.
    • For GridView.builder, use ReorderableBuilder.builder to implement drag-and-drop.
  • Add smooth animations for adding, removing, or updating items in your grid.

Getting started

import 'package:flutter/material.dart';
import 'package:flutter_reorderable_grid_view/widgets/widgets.dart';

void main() {
  runApp(const MaterialApp(home: MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _scrollController = ScrollController();
  final _gridViewKey = GlobalKey();
  
  var _fruits = <String>["apple", "banana", "strawberry"];

  @override
  Widget build(BuildContext context) {
    final generatedChildren = List.generate(
      _fruits.length,
              (index) => Container(
        key: Key(_fruits.elementAt(index)),
        color: Colors.lightBlue,
        child: Text(
          _fruits.elementAt(index),
        ),
      ),
    );

    return Scaffold(
      body: ReorderableBuilder(
        children: generatedChildren,
        scrollController: _scrollController,
        onReorder: (ReorderedListFunction reorderedListFunction) {
          setState(() {
            _fruits = reorderedListFunction(_fruits) as List<String>;
          });
        },
        builder: (children) {
          return GridView(
            key: _gridViewKey,
            controller: _scrollController,
            children: children,
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 4,
              mainAxisSpacing: 4,
              crossAxisSpacing: 8,
            ),
          );
        },
      ),
    );
  }
}

Usage

ReorderableBuilder provides two main functionalities: Drag and Drop and Animations.

To use this widget, wrap ReorderableBuilder around your GridView. For more details, refer to the Getting Started section.

Important: Ensure each child within the GridView has a unique key.

ScrollController

When using a scrollable GridView, ReorderableBuilder requires a ScrollController. This means you must assign the ScrollController to both the scrollable widget and ReorderableBuilder.

For more details, check out the example in inner_scrollable_example.dart.

If the parent is a scrollable widget, you should not assign a ScrollController. In this case, the widget automatically looks up the ScrollController. Assigning one manually can cause issues with drag-and-drop functionality.

For more details, check out the example in outer_scrollable_example.dart.

If no ScrollController is assigned and no ScrollController is found within the context, it indicates that the GridView is not scrollable.

For more details, check out the example in no_scrollable_example.dart.

Drag and Drop

The drag-and-drop functionality is enabled by default.

To ensure proper reordering, you must implement the onReorder callback to update your list of children. Without this, the reorder operation will not work and may cause issues.

Scroll while dragging

While dragging a child, moving it to the top or bottom of your GridView will trigger automatic scrolling.

You can disable this behavior by setting enableScrollingWhileDragging to false.

Animations

Types of Animations

There are two types of animations:

Drag and Drop:

This animation ensures smooth positioning of the dragged child to any position (unless the position is locked). While dragging, the movement of the other children is also animated.

List Updates:

These animations occur when updating your list of children by adding, removing, or modifying items. For example, adding or removing a child at the beginning of the list affects the positions of all subsequent children (See the GIFs at the top of the page for examples).

Supported Widgets
  • Using ReorderableBuilder supports

    • GridView
    • GridView.count
    • GridView.extent
  • Using ReorderableBuilder.builder supports

    • GridView.builder
Parameters
Parameter Description Default Value
children Displays all given children that are build inside a Wrap or GridView. Don't forget a unique key for every child. -
childBuilder Enable support for [GridView.builder] using this function. Don't forget a unique key for every child. -
lockedIndices Define all children that can't be moved while dragging. You need to add the index of this child in a list. []
nonDraggableIndices Specify indices for [children] that are not draggable. []
animationConfig Configuration for all child animations (fade in, position changes, drag feedback, release animation). const ReorderableAnimationConfig()
enableLongPress Deprecated. Use longPressDelay; for immediate drag set Duration.zero. true
longPressDelay Specify the duration before dragging starts after long-pressing the widget. 500 ms
enableDraggable Enables the drag and drop functionality. true
enableScrollingWhileDragging Enables the functionality to scroll while dragging a child to the top or bottom. true
automaticScrollExtent Defines the height of the top or bottom before the dragged child indicates a scrolling. 150.0
dragChildBoxDecoration When a child is dragged, you can override the default BoxDecoration of the dragged child. -
reverse Handles the reversed order of your children. Ensure to add this flag to your scrollable and this widget. false
builder It's required to use [ReorderableBuilder] to obtain updated [children]. -
onReorder After releasing the dragged child, [onReorder] is called which contains a function as parameter to reorder all items. -
onDragStarted Callback when dragging starts with the index where it started. -
onDragEnd Callback when the dragged child was released with the index. -
onUpdatedDraggedChild Called when the dragged child has updated his position while dragging. -
scrollController ScrollController which should be also assigned to the scrollable widget. Don't forget this to prevent animation issues. -
AnimationConfig Parameters

Use animationConfig to configure all animation durations and curves in one place.

Parameter Description Default Value
positionChangeDuration Duration for item position changes outside active dragging. 200 ms
draggingPositionChangeDuration Duration for item position changes while dragging. 200 ms
releasedItemDuration Duration for the released dragged item to animate to its final position. 150 ms
fadeInDuration Duration for fade-in when a new child is added. 500 ms
dragFeedbackDuration Duration for scaling the drag feedback widget. 150 ms
positionChangeCurve Curve for positionChangeDuration. Falls back to defaultAnimationCurve when null. -
draggingPositionChangeCurve Curve for draggingPositionChangeDuration. Falls back to defaultAnimationCurve when null. -
releasedItemCurve Curve for releasedItemDuration. Falls back to defaultAnimationCurve when null. -
fadeInCurve Curve for fadeInDuration. Falls back to defaultAnimationCurve when null. -
dragFeedbackCurve Curve for dragFeedbackDuration. Falls back to defaultAnimationCurve, then to Curves.linear if still null. Curves.linear
defaultAnimationCurve Global fallback curve for animation curve parameters when a specific curve is not provided. -
enableAnimations Enables or disables animations globally. If false, durations become Duration.zero and nullable curves resolve to null. true
CustomDraggable

The CustomDraggable widget is a helper that can contain optional information to be added to Draggable or LongPressDraggable.

Ensure this widget wraps the child you intend to add to your GridView, as it should receive the unique key.

  CustomDraggable(
    // add your unique key here
    key: Key('unique'),
    // will be passed to `Draggable` or `LongPressDraggable`
    data: 'data',
    child: Placeholder(),
  ),

Road map for release of version 6.0.0

  • Code Refactoring for easier understanding!

  • Support for Wrap

    • with animation when adding or removing items
    • drag and drop
    • Github Issue #28

Future Plans

If you have feature requests or have found any issues, please feel free to open an issue on the GitHub project repository.

Contributions are also highly appreciated! If you'd like to contribute a new feature or bug fix, opening a pull request is the way to go. This helps in getting updates and fixes out faster.

Thank you for using this package!

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト