GridView 내 항목을 애니메이션 효과와 드래그 앤 드롭으로 재정렬할 수 있는 플러터 패키지입니다. 타일을 재정렬하거나 그리드의 자식 요소를 업데이트할 때 부드러운 전환 효과를 제공하여 그리드 기반 레이아웃에서 사용자 상호작용을 향상시킵니다. 대시보드, 사진 갤러리 또는 사용자 정의 인터페이스와 같은 동적이고 상호작용적인 그리드가 필요한 앱에 적합합니다. 이 패키지는 모바일, 웹, 데스크톱을 포함한 모든 주요 플랫폼을 지원합니다.
사용 사례
인터랙티브 대시보드 레이아웃
사진 또는 미디어 갤러리 재정렬
사용자 지정 가능한 UI 그리드
드래그 앤 드롭 작업 관리
동적 콘텐츠 재정렬
주요 기능
애니메이션 드래그 앤 드롭 재정렬
재배치 시 부드러운 전환
모든 플러터 플랫폼을 지원합니다
기존 GridView와의 간편한 통합
동적 자식 업데이트 처리
적합한 대상
인터랙티브 그리드 인터페이스를 구축하는 개발자
사용자 중심 콘텐츠 배치가 필요한 앱
크로스 플랫폼 그리드 애플리케이션
자주 레이아웃이 변경되는 UI
고려 사항
매우 큰 데이터 세트를 사용할 경우 성능이 저하될 수 있습니다
항목 키를 주의 깊게 다뤄야 합니다
매우 높은 주파수 업데이트에 최적화되지 않음
기본 드래그 동작 외의 사용자 정의가 제한되어 있음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
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.
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(),
),
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.