Skip to content

Commit

Permalink
Fixes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
letsar committed Sep 17, 2018
1 parent fea4abf commit 84bb9d1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.7
### Fixed
* https://github.com/letsar/flutter_slidable/issues/31 (Issue with dismiss animation).

## 0.4.6
### Modified
* Reduce the possibilities for the https://github.com/flutter/flutter/issues/11895 issue to happen.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
```yaml
dependencies:
...
flutter_slidable: "^0.4.6"
flutter_slidable: "^0.4.7"
```
In your library add the following import:
Expand All @@ -39,7 +39,9 @@ import 'package:flutter_slidable/flutter_slidable.dart';
For help getting started with Flutter, view the online [documentation](https://flutter.io/).

### Constructors

You can create a `Slidable` in two different ways:

* By calling the `Slidable` constructor and passing a list of slide actions.
* By calling the `Slidable.builder` constructor and passing slide action builders, if you want special effects during the animation.

Expand Down
27 changes: 26 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,32 @@ class _MyHomePageState extends State<MyHomePage> {
? Colors.blue
: Colors.green),
icon: Icons.archive,
onTap: () => _showSnackBar(context, 'Archive'),
onTap: () async {
var state = Slidable.of(context);
var dismiss = await showDialog<bool>(
context: context,
builder: (context) {
return new AlertDialog(
title: new Text('Delete'),
content: new Text('Item will be deleted'),
actions: <Widget>[
new FlatButton(
child: new Text('Cancel'),
onPressed: () => Navigator.of(context).pop(false),
),
new FlatButton(
child: new Text('Ok'),
onPressed: () => Navigator.of(context).pop(true),
),
],
);
},
);

if (dismiss) {
state.dismiss();
}
},
);
} else {
return new IconSlideAction(
Expand Down
17 changes: 12 additions & 5 deletions lib/src/widgets/slidable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ class SlidableState extends State<Slidable>
ScrollPosition _scrollPosition;
bool _dragUnderway = false;
Size _sizePriorToCollapse;
bool _dismissing = false;

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

void close() {
_actionsMoveController.fling(velocity: -1.0);
_overallMoveController.fling(velocity: -1.0);
if (!_dismissing) {
_actionsMoveController.fling(velocity: -1.0);
_overallMoveController.fling(velocity: -1.0);
}
}

void dismiss({SlideActionType actionType}) {
if (dismissible) {
_dismissing = true;
actionType ??= this.actionType;
if (actionType != this.actionType) {
setState(() {
Expand Down Expand Up @@ -1003,10 +1007,13 @@ class SlidableState extends State<Slidable>
if (widget.slideToDismissDelegate.onWillDismiss == null ||
await widget.slideToDismissDelegate.onWillDismiss(actionType)) {
_startResizeAnimation();
} else if (widget.slideToDismissDelegate?.closeOnCanceled == true) {
close();
} else {
open();
_dismissing = false;
if (widget.slideToDismissDelegate?.closeOnCanceled == true) {
close();
} else {
open();
}
}
}
updateKeepAlive();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_slidable
description: A Flutter implementation of slidable list item with directional slide actions that can be dismissed.
version: 0.4.6
version: 0.4.7
author: Romain Rastel <lets4r@gmail.com>
homepage: https://github.com/letsar/flutter_slidable

Expand Down

0 comments on commit 84bb9d1

Please sign in to comment.