diff --git a/CHANGELOG.md b/CHANGELOG.md index f00f751e..7931666a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 309d86a9..ecab99ca 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. diff --git a/example/lib/main.dart b/example/lib/main.dart index 4c4d3fb3..5a199ff5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -234,7 +234,32 @@ class _MyHomePageState extends State { ? Colors.blue : Colors.green), icon: Icons.archive, - onTap: () => _showSnackBar(context, 'Archive'), + onTap: () async { + var state = Slidable.of(context); + var dismiss = await showDialog( + context: context, + builder: (context) { + return new AlertDialog( + title: new Text('Delete'), + content: new Text('Item will be deleted'), + actions: [ + 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( diff --git a/lib/src/widgets/slidable.dart b/lib/src/widgets/slidable.dart index bc924f68..6642438c 100644 --- a/lib/src/widgets/slidable.dart +++ b/lib/src/widgets/slidable.dart @@ -812,6 +812,7 @@ class SlidableState extends State ScrollPosition _scrollPosition; bool _dragUnderway = false; Size _sizePriorToCollapse; + bool _dismissing = false; SlideActionType get actionType => dragSign > 0 ? SlideActionType.primary : SlideActionType.secondary; @@ -902,12 +903,15 @@ class SlidableState extends State } 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(() { @@ -1003,10 +1007,13 @@ class SlidableState extends State 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(); diff --git a/pubspec.yaml b/pubspec.yaml index d3f1220c..1c1abf8e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 homepage: https://github.com/letsar/flutter_slidable