From 0e376ed8e20c970a4ab00dcc97a59843771d0891 Mon Sep 17 00:00:00 2001 From: Hamed Abbasi Date: Sat, 21 Sep 2024 14:17:05 +0330 Subject: [PATCH 1/4] Add onSwap function to return DragUpdateDetails value --- lib/src/gesture_detector.dart | 3 +++ lib/src/slidable.dart | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/src/gesture_detector.dart b/lib/src/gesture_detector.dart index 8a82712..8a90dc3 100644 --- a/lib/src/gesture_detector.dart +++ b/lib/src/gesture_detector.dart @@ -13,10 +13,12 @@ class SlidableGestureDetector extends StatefulWidget { required this.controller, required this.direction, required this.child, + this.onSwap, this.dragStartBehavior = DragStartBehavior.start, }); final SlidableController controller; + final Function(DragUpdateDetails detail)? onSwap; final Widget child; final Axis direction; final bool enabled; @@ -88,6 +90,7 @@ class _SlidableGestureDetectorState extends State { dragExtent += delta; lastPosition = details.localPosition; widget.controller.ratio = dragExtent / overallDragAxisExtent; + widget.onSwap?.call(details); } void handleDragEnd(DragEndDetails details) { diff --git a/lib/src/slidable.dart b/lib/src/slidable.dart index a0a3804..2e6a640 100644 --- a/lib/src/slidable.dart +++ b/lib/src/slidable.dart @@ -1,3 +1,5 @@ +// ignore_for_file: public_member_api_docs + import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_slidable/src/auto_close_behavior.dart'; @@ -28,9 +30,15 @@ class Slidable extends StatefulWidget { this.direction = Axis.horizontal, this.dragStartBehavior = DragStartBehavior.down, this.useTextDirection = true, + this.onSwap, required this.child, }); + /// You can find out if the item is being [swapped] or not + /// + /// You also have the [DragUpdateDetails] value + final Function(DragUpdateDetails detail)? onSwap; + /// The Slidable widget controller. final SlidableController? controller; @@ -274,6 +282,7 @@ class _SlidableState extends State controller: controller, direction: widget.direction, dragStartBehavior: widget.dragStartBehavior, + child: SlidableNotificationSender( tag: widget.groupTag, controller: controller, From eebd89ea4df5bfec1d97b5ed387b411bd5bfda19 Mon Sep 17 00:00:00 2001 From: Hamed Abbasi Date: Sat, 21 Sep 2024 14:19:19 +0330 Subject: [PATCH 2/4] Add void return type --- lib/src/gesture_detector.dart | 2 +- lib/src/slidable.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/gesture_detector.dart b/lib/src/gesture_detector.dart index 8a90dc3..b339dbd 100644 --- a/lib/src/gesture_detector.dart +++ b/lib/src/gesture_detector.dart @@ -18,7 +18,7 @@ class SlidableGestureDetector extends StatefulWidget { }); final SlidableController controller; - final Function(DragUpdateDetails detail)? onSwap; + final void Function(DragUpdateDetails detail)? onSwap; final Widget child; final Axis direction; final bool enabled; diff --git a/lib/src/slidable.dart b/lib/src/slidable.dart index 2e6a640..750429b 100644 --- a/lib/src/slidable.dart +++ b/lib/src/slidable.dart @@ -37,7 +37,7 @@ class Slidable extends StatefulWidget { /// You can find out if the item is being [swapped] or not /// /// You also have the [DragUpdateDetails] value - final Function(DragUpdateDetails detail)? onSwap; + final void Function(DragUpdateDetails detail)? onSwap; /// The Slidable widget controller. final SlidableController? controller; From c1af59295765e61cb0c3191a7ba6fadfb819b59c Mon Sep 17 00:00:00 2001 From: Hamed Abbasi Date: Sat, 21 Sep 2024 14:49:10 +0330 Subject: [PATCH 3/4] set SlidableGestureDetector --- lib/src/slidable.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/slidable.dart b/lib/src/slidable.dart index 750429b..8864d65 100644 --- a/lib/src/slidable.dart +++ b/lib/src/slidable.dart @@ -282,7 +282,7 @@ class _SlidableState extends State controller: controller, direction: widget.direction, dragStartBehavior: widget.dragStartBehavior, - + onSwap: widget.onSwap, child: SlidableNotificationSender( tag: widget.groupTag, controller: controller, From 51a16d3af4a71e2214ebd1e74c2bf8fd3df26137 Mon Sep 17 00:00:00 2001 From: Hamed Abbasi Date: Sat, 21 Sep 2024 14:52:26 +0330 Subject: [PATCH 4/4] add onSwap main.dart example --- example/android/build.gradle | 4 ++-- example/lib/main.dart | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/example/android/build.gradle b/example/android/build.gradle index 83ae220..6617c1e 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.7.0' repositories { google() mavenCentral() @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/lib/main.dart b/example/lib/main.dart index 76506f9..0a3d619 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -26,6 +26,11 @@ class _MyAppState extends State with SingleTickerProviderStateMixin { // Specify a key if the Slidable is dismissible. key: const ValueKey(0), + // You can access the DragUpdateDetails value + onSwap: (detail) { + print(detail); + }, + // The start action pane is the one at the left or the top side. startActionPane: ActionPane( // A motion is a widget used to control how the pane animates.