Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/animated_reorderable_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export 'src/animated_reorderable_listview.dart';

//Direct access to the sliver builder, circumventing the ScrollView layer
export 'src/builder/reorderable_animated_list_impl.dart';
//Direct access to the ReorderableGridDragStartListener, if required when
//addDragStartListener false
export 'src/component/drag_listener.dart';
26 changes: 24 additions & 2 deletions lib/src/animated_gridview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ class AnimatedGridView<E extends Object> extends StatefulWidget {
/// Defaults to true.
final bool enableSwap;

/// Whether to add a [ReorderableGridDragStartListener] to the reorderable ItemBuilder.
///
/// Defaults to true.
///
/// If set to false, the items in ItemBuilder will not respond to pointer down events,
/// which means they won't be draggable. This can be useful if you still want to
/// receive item pointer events, and add your custom drag start listener
/// to the item widget.
///
/// Example:
/// ```dart
/// ReorderableGridDragStartListener(
/// index: dragIndex,
/// child: const Icon(
/// Icons.drag_handle_outlined,
/// ),
/// ),
/// ```
final bool addDragStartListener;

/// Creates a [AnimatedGridView] that animates insertion and removal of the item.
const AnimatedGridView(
{Key? key,
Expand All @@ -311,7 +331,8 @@ class AnimatedGridView<E extends Object> extends StatefulWidget {
this.removeItemBuilder,
this.shrinkWrap = false,
required this.isSameItem,
this.enableSwap = true})
this.enableSwap = true,
this.addDragStartListener = true})
: super(key: key);

/// The state from the closest instance of this class that encloses the given
Expand Down Expand Up @@ -392,7 +413,8 @@ class AnimatedGridViewState<E extends Object>
insertItemBuilder: widget.insertItemBuilder,
removeItemBuilder: widget.removeItemBuilder,
isSameItem: widget.isSameItem,
enableSwap: widget.enableSwap),
enableSwap: widget.enableSwap,
addDragStartListener: widget.addDragStartListener),
),
]);
}
Expand Down
22 changes: 22 additions & 0 deletions lib/src/animated_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,26 @@ class AnimatedListView<E extends Object> extends StatefulWidget {
/// Defaults to true.
final bool enableSwap;

/// Whether to add a [ReorderableGridDragStartListener] to the reorderable ItemBuilder.
///
/// Defaults to true.
///
/// If set to false, the items in ItemBuilder will not respond to pointer down events,
/// which means they won't be draggable. This can be useful if you still want to
/// receive item pointer events, and add your custom drag start listener
/// to the item widget.
///
/// Example:
/// ```dart
/// ReorderableGridDragStartListener(
/// index: dragIndex,
/// child: const Icon(
/// Icons.drag_handle_outlined,
/// ),
/// ),
/// ```
final bool addDragStartListener;

/// Creates a [AnimatedListView] that animates insertion and removal of the item.
const AnimatedListView({
Key? key,
Expand All @@ -308,6 +328,7 @@ class AnimatedListView<E extends Object> extends StatefulWidget {
this.shrinkWrap = false,
required this.isSameItem,
this.enableSwap = true,
this.addDragStartListener = true,
}) : super(key: key);

/// The state from the closest instance of this class that encloses the given
Expand Down Expand Up @@ -388,6 +409,7 @@ class AnimatedListViewState<E extends Object>
removeItemBuilder: widget.removeItemBuilder,
isSameItem: widget.isSameItem,
enableSwap: widget.enableSwap,
addDragStartListener: widget.addDragStartListener,
),
),
]);
Expand Down
24 changes: 23 additions & 1 deletion lib/src/animated_reorderable_gridview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,26 @@ class AnimatedReorderableGridView<E extends Object> extends StatefulWidget {
/// Defaults to true.
final bool enableSwap;

/// Whether to add a [ReorderableGridDragStartListener] to the reorderable ItemBuilder.
///
/// Defaults to true.
///
/// If set to false, the items in ItemBuilder will not respond to pointer down events,
/// which means they won't be draggable. This can be useful if you still want to
/// receive item pointer events, and add your custom drag start listener
/// to the item widget.
///
/// Example:
/// ```dart
/// ReorderableGridDragStartListener(
/// index: dragIndex,
/// child: const Icon(
/// Icons.drag_handle_outlined,
/// ),
/// ),
/// ```
final bool addDragStartListener;

/// Creates a [AnimatedReorderableGridView] that enables users to interactively reorder items through dragging,
/// with animated insertion and removal of items.
const AnimatedReorderableGridView(
Expand Down Expand Up @@ -381,7 +401,8 @@ class AnimatedReorderableGridView<E extends Object> extends StatefulWidget {
this.dragStartDelay = const Duration(milliseconds: 500),
this.nonDraggableItems = const [],
this.lockedItems = const [],
this.enableSwap = true})
this.enableSwap = true,
this.addDragStartListener = true})
: super(key: key);

/// The state from the closest instance of this class that encloses the given
Expand Down Expand Up @@ -473,6 +494,7 @@ class AnimatedReorderableGridViewState<E extends Object>
nonDraggableItems: widget.nonDraggableItems,
lockedItems: widget.lockedItems,
enableSwap: widget.enableSwap,
addDragStartListener: widget.addDragStartListener,
),
),
]);
Expand Down
22 changes: 22 additions & 0 deletions lib/src/animated_reorderable_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,26 @@ class AnimatedReorderableListView<E extends Object> extends StatefulWidget {
/// Defaults to true.
final bool enableSwap;

/// Whether to add a [ReorderableGridDragStartListener] to the reorderable ItemBuilder.
///
/// Defaults to true.
///
/// If set to false, the items in ItemBuilder will not respond to pointer down events,
/// which means they won't be draggable. This can be useful if you still want to
/// receive item pointer events, and add your custom drag start listener
/// to the item widget.
///
/// Example:
/// ```dart
/// ReorderableGridDragStartListener(
/// index: dragIndex,
/// child: const Icon(
/// Icons.drag_handle_outlined,
/// ),
/// ),
/// ```
final bool addDragStartListener;

/// Creates a [AnimatedReorderableListView] that enables users to interactively reorder items through dragging,
/// with animated insertion and removal of items.
const AnimatedReorderableListView({
Expand Down Expand Up @@ -400,6 +420,7 @@ class AnimatedReorderableListView<E extends Object> extends StatefulWidget {
this.nonDraggableItems = const [],
this.lockedItems = const [],
this.enableSwap = true,
this.addDragStartListener = true,
}) : super(key: key);

/// The state from the closest instance of this class that encloses the given
Expand Down Expand Up @@ -491,6 +512,7 @@ class AnimatedReorderableListViewState<E extends Object>
nonDraggableItems: widget.nonDraggableItems,
lockedItems: widget.lockedItems,
enableSwap: widget.enableSwap,
addDragStartListener: widget.addDragStartListener,
),
),
]);
Expand Down
12 changes: 11 additions & 1 deletion lib/src/builder/reorderable_animated_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ReorderableAnimatedBuilder<E> extends StatefulWidget {
final Duration dragStartDelay;
final List<int> nonDraggableIndices;
final List<int> lockedIndices;
final bool addDragStartListener;

const ReorderableAnimatedBuilder(
{Key? key,
Expand All @@ -49,7 +50,8 @@ class ReorderableAnimatedBuilder<E> extends StatefulWidget {
this.longPressDraggable = false,
required this.dragStartDelay,
required this.nonDraggableIndices,
required this.lockedIndices})
required this.lockedIndices,
required this.addDragStartListener})
: assert(initialCount >= 0),
super(key: key);

Expand Down Expand Up @@ -848,6 +850,14 @@ class ReorderableAnimatedBuilderState extends State<ReorderableAnimatedBuilder>
return true;
}());
final Key itemGlobalKey = _MotionBuilderItemGlobalKey(item.key!, this);

if (!widget.addDragStartListener) {
return SizedBox(
key: itemGlobalKey,
child: itemWithSemantics,
);
}

if (widget.buildDefaultDragHandles) {
switch (Theme.of(context).platform) {
case TargetPlatform.linux:
Expand Down
8 changes: 7 additions & 1 deletion lib/src/builder/reorderable_animated_list_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ abstract class ReorderableAnimatedListBase<W extends Widget, E extends Object>
final List<E> nonDraggableItems;
final List<E> lockedItems;
final bool enableSwap;
final bool addDragStartListener;

const ReorderableAnimatedListBase(
{Key? key,
Expand All @@ -61,7 +62,8 @@ abstract class ReorderableAnimatedListBase<W extends Widget, E extends Object>
this.dragStartDelay,
this.enableSwap = true,
required this.nonDraggableItems,
required this.lockedItems})
required this.lockedItems,
this.addDragStartListener = true})
: assert(itemBuilder != null),
super(key: key);
}
Expand Down Expand Up @@ -179,6 +181,10 @@ abstract class ReorderableAnimatedListBaseState<
.map((entry) => entry.key)
.toList();

@nonVirtual
@protected
bool get addDragStartListener => widget.addDragStartListener;

@override
void initState() {
super.initState();
Expand Down
9 changes: 7 additions & 2 deletions lib/src/builder/reorderable_animated_list_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ReorderableAnimatedListImpl<E extends Object>
List<E> nonDraggableItems = const [],
List<E> lockedItems = const [],
bool enableSwap = true,
bool addDragStartListener = true,
}) : super(
key: key,
items: items,
Expand All @@ -49,7 +50,8 @@ class ReorderableAnimatedListImpl<E extends Object>
dragStartDelay: dragStartDelay,
nonDraggableItems: nonDraggableItems,
lockedItems: lockedItems,
enableSwap: enableSwap);
enableSwap: enableSwap,
addDragStartListener: addDragStartListener);

const ReorderableAnimatedListImpl.grid({
Key? key,
Expand All @@ -74,6 +76,7 @@ class ReorderableAnimatedListImpl<E extends Object>
List<E> nonDraggableItems = const [],
List<E> lockedItems = const [],
bool enableSwap = true,
bool addDragStartListener = true,
}) : super(
key: key,
items: items,
Expand All @@ -96,7 +99,8 @@ class ReorderableAnimatedListImpl<E extends Object>
dragStartDelay: dragStartDelay,
nonDraggableItems: nonDraggableItems,
lockedItems: lockedItems,
enableSwap: enableSwap);
enableSwap: enableSwap,
addDragStartListener: addDragStartListener);

@override
ReorderableAnimatedListImplState<E> createState() =>
Expand Down Expand Up @@ -127,6 +131,7 @@ class ReorderableAnimatedListImplState<E extends Object>
dragStartDelay: dragStartDelay,
nonDraggableIndices: nonDraggableItems,
lockedIndices: lockedIndices,
addDragStartListener: addDragStartListener,
);
}
}