Skip to content

Commit 84bb9d1

Browse files
committed
Fixes #31
1 parent fea4abf commit 84bb9d1

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.7
2+
### Fixed
3+
* https://github.com/letsar/flutter_slidable/issues/31 (Issue with dismiss animation).
4+
15
## 0.4.6
26
### Modified
37
* Reduce the possibilities for the https://github.com/flutter/flutter/issues/11895 issue to happen.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
2727
```yaml
2828
dependencies:
2929
...
30-
flutter_slidable: "^0.4.6"
30+
flutter_slidable: "^0.4.7"
3131
```
3232
3333
In your library add the following import:
@@ -39,7 +39,9 @@ import 'package:flutter_slidable/flutter_slidable.dart';
3939
For help getting started with Flutter, view the online [documentation](https://flutter.io/).
4040

4141
### Constructors
42+
4243
You can create a `Slidable` in two different ways:
44+
4345
* By calling the `Slidable` constructor and passing a list of slide actions.
4446
* By calling the `Slidable.builder` constructor and passing slide action builders, if you want special effects during the animation.
4547

example/lib/main.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,32 @@ class _MyHomePageState extends State<MyHomePage> {
234234
? Colors.blue
235235
: Colors.green),
236236
icon: Icons.archive,
237-
onTap: () => _showSnackBar(context, 'Archive'),
237+
onTap: () async {
238+
var state = Slidable.of(context);
239+
var dismiss = await showDialog<bool>(
240+
context: context,
241+
builder: (context) {
242+
return new AlertDialog(
243+
title: new Text('Delete'),
244+
content: new Text('Item will be deleted'),
245+
actions: <Widget>[
246+
new FlatButton(
247+
child: new Text('Cancel'),
248+
onPressed: () => Navigator.of(context).pop(false),
249+
),
250+
new FlatButton(
251+
child: new Text('Ok'),
252+
onPressed: () => Navigator.of(context).pop(true),
253+
),
254+
],
255+
);
256+
},
257+
);
258+
259+
if (dismiss) {
260+
state.dismiss();
261+
}
262+
},
238263
);
239264
} else {
240265
return new IconSlideAction(

lib/src/widgets/slidable.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ class SlidableState extends State<Slidable>
812812
ScrollPosition _scrollPosition;
813813
bool _dragUnderway = false;
814814
Size _sizePriorToCollapse;
815+
bool _dismissing = false;
815816

816817
SlideActionType get actionType =>
817818
dragSign > 0 ? SlideActionType.primary : SlideActionType.secondary;
@@ -902,12 +903,15 @@ class SlidableState extends State<Slidable>
902903
}
903904

904905
void close() {
905-
_actionsMoveController.fling(velocity: -1.0);
906-
_overallMoveController.fling(velocity: -1.0);
906+
if (!_dismissing) {
907+
_actionsMoveController.fling(velocity: -1.0);
908+
_overallMoveController.fling(velocity: -1.0);
909+
}
907910
}
908911

909912
void dismiss({SlideActionType actionType}) {
910913
if (dismissible) {
914+
_dismissing = true;
911915
actionType ??= this.actionType;
912916
if (actionType != this.actionType) {
913917
setState(() {
@@ -1003,10 +1007,13 @@ class SlidableState extends State<Slidable>
10031007
if (widget.slideToDismissDelegate.onWillDismiss == null ||
10041008
await widget.slideToDismissDelegate.onWillDismiss(actionType)) {
10051009
_startResizeAnimation();
1006-
} else if (widget.slideToDismissDelegate?.closeOnCanceled == true) {
1007-
close();
10081010
} else {
1009-
open();
1011+
_dismissing = false;
1012+
if (widget.slideToDismissDelegate?.closeOnCanceled == true) {
1013+
close();
1014+
} else {
1015+
open();
1016+
}
10101017
}
10111018
}
10121019
updateKeepAlive();

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_slidable
22
description: A Flutter implementation of slidable list item with directional slide actions that can be dismissed.
3-
version: 0.4.6
3+
version: 0.4.7
44
author: Romain Rastel <[email protected]>
55
homepage: https://github.com/letsar/flutter_slidable
66

0 commit comments

Comments
 (0)