Skip to content

Commit 72ecb7b

Browse files
committed
Fixed Dismissible animation issue
1 parent bc53b41 commit 72ecb7b

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.0-dev.8
2+
### Fixed
3+
* Fixes an issue where the Dismissible animation stopped in middle when the gesture was too fast.
4+
15
## 1.0.0-dev.7
26
### Fixed
37
* Fixes an issue where the Slidable animation stopped in middle when the gesture was too fast.

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ packages:
6868
path: ".."
6969
relative: true
7070
source: path
71-
version: "1.0.0-dev.7"
71+
version: "1.0.0-dev.8"
7272
flutter_test:
7373
dependency: "direct dev"
7474
description: flutter

lib/src/action_pane.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
106106
SlidableController? controller;
107107
late double openThreshold;
108108
late double closeThreshold;
109-
bool? showMotion;
109+
bool showMotion = true;
110110

111111
@override
112112
double get extentRatio => widget.extentRatio;
@@ -120,7 +120,6 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
120120
if (widget.dismissible != null) {
121121
controller!.animation.addListener(handleRatioChanged);
122122
}
123-
showMotion = true;
124123
updateThresholds();
125124
controller!.actionPaneConfigurator = this;
126125
}
@@ -173,7 +172,13 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
173172
final position = controller!.animation.value;
174173

175174
if (widget.dismissible != null && position > widget.extentRatio) {
176-
controller!.dismissGesture.value = DismissGesture(gesture);
175+
if (controller!.isDismissibleReady) {
176+
controller!.dismissGesture.value = DismissGesture(gesture);
177+
} else {
178+
// If the dismissible is not ready, the animation will stop.
179+
// So we prefere to open the action pane instead.
180+
controller!.openCurrentActionPane();
181+
}
177182
return;
178183
}
179184

@@ -190,7 +195,8 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
190195
}
191196

192197
void handleRatioChanged() {
193-
final show = controller!.ratio.abs() <= widget.extentRatio;
198+
final show = controller!.ratio.abs() <= widget.extentRatio &&
199+
!controller!.isDismissibleReady;
194200
if (show != showMotion) {
195201
setState(() {
196202
showMotion = show;
@@ -204,7 +210,7 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
204210

205211
Widget? child;
206212

207-
if (showMotion!) {
213+
if (showMotion) {
208214
final factor = widget.extentRatio;
209215
child = FractionallySizedBox(
210216
alignment: config.alignment,

lib/src/controller.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ class SlidableController {
102102
SlidableController(TickerProvider vsync)
103103
: _animationController = AnimationController(vsync: vsync),
104104
endGesture = ValueNotifier(null),
105-
dismissGesture = ValueNotifier(null),
105+
_dismissGesture = _ValueNotifier(null),
106106
resizeRequest = ValueNotifier(null),
107107
actionPaneType = ValueNotifier(ActionPaneType.none) {
108108
_animationController.addListener(_onRatioChanged);
109109
}
110110

111111
final AnimationController _animationController;
112+
final _ValueNotifier<DismissGesture?> _dismissGesture;
112113

113114
/// Whether the start action pane is enabled.
114115
bool enableStartActionPane = true;
@@ -156,14 +157,17 @@ class SlidableController {
156157
final ValueNotifier<EndGesture?> endGesture;
157158

158159
/// Track the dismiss gestures.
159-
final ValueNotifier<DismissGesture?> dismissGesture;
160+
ValueNotifier<DismissGesture?> get dismissGesture => _dismissGesture;
160161

161162
/// Track the resize requests.
162163
final ValueNotifier<ResizeRequest?> resizeRequest;
163164

164165
/// Track the type of the action pane.
165166
final ValueNotifier<ActionPaneType> actionPaneType;
166167

168+
/// Indicates whether the dismissible registered to gestures.
169+
bool get isDismissibleReady => _dismissGesture._hasListeners;
170+
167171
/// Whether this [close()] method has been called and not finished.
168172
bool get closing => _closing;
169173
bool _closing = false;
@@ -323,6 +327,12 @@ class SlidableController {
323327
}
324328
}
325329

330+
class _ValueNotifier<T> extends ValueNotifier<T> {
331+
_ValueNotifier(T value) : super(value);
332+
333+
bool get _hasListeners => hasListeners;
334+
}
335+
326336
/// Extensions for [ActionPaneType].
327337
extension ActionPaneTypeX on ActionPaneType {
328338
/// Transforms this [ActionPaneType] to a sign.

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: 1.0.0-dev.7
3+
version: 1.0.0-dev.8
44
homepage: https://github.com/letsar/flutter_slidable
55

66
environment:

0 commit comments

Comments
 (0)