From edbbf510b511e98c96f88c02d0d4666d5d4d8d56 Mon Sep 17 00:00:00 2001 From: cp-sneha-s Date: Mon, 1 Jul 2024 19:56:51 +0530 Subject: [PATCH 1/2] Fix last item animation --- example/lib/home_page.dart | 3 +- example/pubspec.lock | 30 +++++----- lib/src/animated_reorderable_gridview.dart | 5 ++ lib/src/animated_reorderable_listview.dart | 58 +++++++++++--------- lib/src/builder/motion_animated_builder.dart | 14 ++++- lib/src/builder/motion_list_base.dart | 8 ++- lib/src/builder/motion_list_impl.dart | 13 +++-- 7 files changed, 82 insertions(+), 49 deletions(-) diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index 4a8378e..1f61390 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -45,7 +45,8 @@ class _HomePageState extends State { addedNumber += 1; setState(() { - list.insert(1, User(name: "User $addedNumber", index: addedNumber)); + list.insert( + list.length, User(name: "User $addedNumber", index: addedNumber)); }); } diff --git a/example/pubspec.lock b/example/pubspec.lock index 795fd36..9def1fe 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "1.0.2" + version: "1.0.6" async: dependency: transitive description: @@ -86,26 +86,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.3" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" lints: dependency: transitive description: @@ -134,10 +134,10 @@ packages: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.12.0" path: dependency: transitive description: @@ -195,10 +195,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" vector_math: dependency: transitive description: @@ -211,10 +211,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.1" sdks: - dart: ">=3.2.0-0 <4.0.0" - flutter: ">=1.17.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/lib/src/animated_reorderable_gridview.dart b/lib/src/animated_reorderable_gridview.dart index 4067cc7..bedf31f 100644 --- a/lib/src/animated_reorderable_gridview.dart +++ b/lib/src/animated_reorderable_gridview.dart @@ -176,6 +176,9 @@ class AnimatedReorderableGridView extends StatelessWidget { /// transition for the widget that is built. final AnimatedWidgetBuilder? removeItemBuilder; + /// Whether the items can be dragged by long pressing on them. + final bool longPressDraggable; + const AnimatedReorderableGridView({ Key? key, required this.items, @@ -200,6 +203,7 @@ class AnimatedReorderableGridView extends StatelessWidget { this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, this.dragStartBehavior = DragStartBehavior.start, this.clipBehavior = Clip.hardEdge, + this.longPressDraggable = true, this.insertItemBuilder, this.removeItemBuilder, }) : super(key: key); @@ -235,6 +239,7 @@ class AnimatedReorderableGridView extends StatelessWidget { scrollDirection: scrollDirection, insertItemBuilder: insertItemBuilder, removeItemBuilder: removeItemBuilder, + longPressDraggable: longPressDraggable, ), ), ]); diff --git a/lib/src/animated_reorderable_listview.dart b/lib/src/animated_reorderable_listview.dart index 9634544..2c63d0a 100644 --- a/lib/src/animated_reorderable_listview.dart +++ b/lib/src/animated_reorderable_listview.dart @@ -188,33 +188,36 @@ class AnimatedReorderableListView extends StatefulWidget { /// transition for the widget that is built. final AnimatedWidgetBuilder? removeItemBuilder; - const AnimatedReorderableListView( - {Key? key, - required this.items, - required this.itemBuilder, - required this.onReorder, - this.enterTransition, - this.exitTransition, - this.insertDuration, - this.removeDuration, - this.onReorderStart, - this.onReorderEnd, - this.proxyDecorator, - this.scrollDirection = Axis.vertical, - this.padding, - this.reverse = false, - this.controller, - this.primary, - this.physics, - this.scrollBehavior, - this.restorationId, - this.buildDefaultDragHandles = true, - this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, - this.dragStartBehavior = DragStartBehavior.start, - this.clipBehavior = Clip.hardEdge, - this.insertItemBuilder, - this.removeItemBuilder}) - : super(key: key); + final bool longPressDraggable; + + const AnimatedReorderableListView({ + Key? key, + required this.items, + required this.itemBuilder, + required this.onReorder, + this.enterTransition, + this.exitTransition, + this.insertDuration, + this.removeDuration, + this.onReorderStart, + this.onReorderEnd, + this.proxyDecorator, + this.scrollDirection = Axis.vertical, + this.padding, + this.reverse = false, + this.controller, + this.primary, + this.physics, + this.scrollBehavior, + this.restorationId, + this.buildDefaultDragHandles = true, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + this.dragStartBehavior = DragStartBehavior.start, + this.clipBehavior = Clip.hardEdge, + this.insertItemBuilder, + this.removeItemBuilder, + this.longPressDraggable = true, + }) : super(key: key); @override State> createState() => @@ -254,6 +257,7 @@ class _AnimatedReorderableListViewState scrollDirection: widget.scrollDirection, insertItemBuilder: widget.insertItemBuilder, removeItemBuilder: widget.removeItemBuilder, + longPressDraggable: widget.longPressDraggable, ), ), ]); diff --git a/lib/src/builder/motion_animated_builder.dart b/lib/src/builder/motion_animated_builder.dart index 0b94a17..944ea7e 100644 --- a/lib/src/builder/motion_animated_builder.dart +++ b/lib/src/builder/motion_animated_builder.dart @@ -29,6 +29,7 @@ class MotionBuilder extends StatefulWidget { final Axis scrollDirection; final SliverGridDelegate? delegateBuilder; final bool buildDefaultDragHandles; + final bool longPressDraggable; const MotionBuilder( {Key? key, @@ -42,7 +43,8 @@ class MotionBuilder extends StatefulWidget { this.initialCount = 0, this.delegateBuilder, this.scrollDirection = Axis.vertical, - required this.buildDefaultDragHandles}) + required this.buildDefaultDragHandles, + this.longPressDraggable = false}) : assert(initialCount >= 0), super(key: key); @@ -504,6 +506,7 @@ class MotionBuilderState extends State }); } else { childrenMap[itemIndex] = motionData; + sizeController.value = kAlwaysCompleteAnimation.value; controller.forward().then((_) { _removeActiveItemAt(_incomingItems, incomingItem.itemIndex)! .controller! @@ -692,6 +695,14 @@ class MotionBuilderState extends State return true; }()); final Key itemGlobalKey = _MotionBuilderItemGlobalKey(item.key!, this); + + if (!widget.longPressDraggable) { + return ReorderableGridDragStartListener( + key: itemGlobalKey, + index: index, + child: itemWithSemantics, + ); + } if (widget.buildDefaultDragHandles) { switch (Theme.of(context).platform) { case TargetPlatform.linux: @@ -835,6 +846,7 @@ class MotionBuilderState extends State final Animation sizeAnimation = incomingItem?.sizeAnimation ?? kAlwaysCompleteAnimation; return SizeTransition( + axis: widget.scrollDirection, sizeFactor: sizeAnimation, child: widget.insertAnimationBuilder(context, child, animation)); } diff --git a/lib/src/builder/motion_list_base.dart b/lib/src/builder/motion_list_base.dart index cc0dd51..245e02f 100644 --- a/lib/src/builder/motion_list_base.dart +++ b/lib/src/builder/motion_list_base.dart @@ -31,6 +31,7 @@ abstract class MotionListBase final AnimatedWidgetBuilder? insertItemBuilder; final AnimatedWidgetBuilder? removeItemBuilder; final bool? buildDefaultDragHandles; + final bool? longPressDraggable; const MotionListBase( {Key? key, @@ -48,7 +49,8 @@ abstract class MotionListBase this.sliverGridDelegate, this.insertItemBuilder, this.removeItemBuilder, - this.buildDefaultDragHandles}) + this.buildDefaultDragHandles, + this.longPressDraggable}) : super(key: key); } @@ -123,6 +125,10 @@ abstract class MotionListBaseState< @protected bool get buildDefaultDragHandles => widget.buildDefaultDragHandles ?? false; + @nonVirtual + @protected + bool get longPressDraggable => widget.longPressDraggable ?? false; + @override void initState() { super.initState(); diff --git a/lib/src/builder/motion_list_impl.dart b/lib/src/builder/motion_list_impl.dart index d97e643..af7b9ce 100644 --- a/lib/src/builder/motion_list_impl.dart +++ b/lib/src/builder/motion_list_impl.dart @@ -20,7 +20,8 @@ class MotionListImpl extends MotionListBase { required Axis scrollDirection, AnimatedWidgetBuilder? insertItemBuilder, AnimatedWidgetBuilder? removeItemBuilder, - bool? buildDefaultDragHandles}) + bool? buildDefaultDragHandles, + bool? longPressDraggable}) : super( key: key, items: items, @@ -36,7 +37,8 @@ class MotionListImpl extends MotionListBase { scrollDirection: scrollDirection, insertItemBuilder: insertItemBuilder, removeItemBuilder: removeItemBuilder, - buildDefaultDragHandles: buildDefaultDragHandles); + buildDefaultDragHandles: buildDefaultDragHandles, + longPressDraggable: longPressDraggable); const MotionListImpl.grid( {Key? key, @@ -54,7 +56,8 @@ class MotionListImpl extends MotionListBase { required Axis scrollDirection, AnimatedWidgetBuilder? insertItemBuilder, AnimatedWidgetBuilder? removeItemBuilder, - bool? buildDefaultDragHandles}) + bool? buildDefaultDragHandles, + bool? longPressDraggable}) : super( key: key, items: items, @@ -71,7 +74,8 @@ class MotionListImpl extends MotionListBase { scrollDirection: scrollDirection, insertItemBuilder: insertItemBuilder, removeItemBuilder: removeItemBuilder, - buildDefaultDragHandles: buildDefaultDragHandles); + buildDefaultDragHandles: buildDefaultDragHandles, + longPressDraggable: longPressDraggable); @override MotionListImplState createState() => MotionListImplState(); @@ -96,6 +100,7 @@ class MotionListImplState scrollDirection: scrollDirection, delegateBuilder: sliverGridDelegate, buildDefaultDragHandles: buildDefaultDragHandles, + longPressDraggable: longPressDraggable, ); } } From 18b6b12fb96859080c24e36a31d05298fa8e4444 Mon Sep 17 00:00:00 2001 From: cp-sneha-s Date: Mon, 1 Jul 2024 20:05:26 +0530 Subject: [PATCH 2/2] Update readme --- CHANGELOG.md | 10 ++++++++++ pubspec.yaml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44a0eda..48899ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +#v1.0.7 + +# Changelog + +## Bug Fixes +- List Will Not Animate When New Item Is Added to the End of the List + +## Enhancement +- Allow Disabling Long Press to Start Reorder Gesture + # v1.0.6 # Changelog diff --git a/pubspec.yaml b/pubspec.yaml index c1459e1..efe58fd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: animated_reorderable_list description: A Flutter Reorderable Animated List with simple implementation and smooth transition. -version: 1.0.6 +version: 1.0.7 repository: https://github.com/canopas/animated_reorderable_list environment: