Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add on swap #502

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.0'
repositories {
google()
mavenCentral()
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
5 changes: 5 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class _MyAppState extends State<MyApp> 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.
Expand Down
3 changes: 3 additions & 0 deletions lib/src/gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 void Function(DragUpdateDetails detail)? onSwap;
final Widget child;
final Axis direction;
final bool enabled;
Expand Down Expand Up @@ -88,6 +90,7 @@ class _SlidableGestureDetectorState extends State<SlidableGestureDetector> {
dragExtent += delta;
lastPosition = details.localPosition;
widget.controller.ratio = dragExtent / overallDragAxisExtent;
widget.onSwap?.call(details);
}

void handleDragEnd(DragEndDetails details) {
Expand Down
9 changes: 9 additions & 0 deletions lib/src/slidable.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 void Function(DragUpdateDetails detail)? onSwap;

/// The Slidable widget controller.
final SlidableController? controller;

Expand Down Expand Up @@ -274,6 +282,7 @@ class _SlidableState extends State<Slidable>
controller: controller,
direction: widget.direction,
dragStartBehavior: widget.dragStartBehavior,
onSwap: widget.onSwap,
child: SlidableNotificationSender(
tag: widget.groupTag,
controller: controller,
Expand Down