Skip to content

Commit 2f698e7

Browse files
committed
Fix animation stopping when to fast
1 parent c583dc7 commit 2f698e7

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

lib/src/action_pane.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
120120
if (widget.dismissible != null) {
121121
controller!.animation.addListener(handleRatioChanged);
122122
}
123-
controller!.actionPaneConfigurator = this;
124123
showMotion = true;
125124
updateThresholds();
125+
controller!.actionPaneConfigurator = this;
126126
}
127127

128128
void updateThresholds() {
@@ -167,6 +167,7 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
167167
return absoluteRatio;
168168
}
169169

170+
@override
170171
void handleEndGestureChanged() {
171172
final gesture = controller!.endGesture.value;
172173
final position = controller!.animation.value;
@@ -181,7 +182,6 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
181182
((gesture.opening && position >= openThreshold) ||
182183
gesture.closing && position > closeThreshold)) {
183184
controller!.openCurrentActionPane();
184-
185185
return;
186186
}
187187

lib/src/controller.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ abstract class RatioConfigurator {
2222

2323
/// The total extent ratio of this configurator.
2424
double get extentRatio;
25+
26+
/// A method to call when the end gesture changed.
27+
void handleEndGestureChanged();
2528
}
2629

2730
/// The direction of a gesture in the context of [Slidable].
@@ -132,7 +135,19 @@ class SlidableController {
132135
}
133136

134137
/// The current action pane configurator.
135-
RatioConfigurator? actionPaneConfigurator;
138+
RatioConfigurator? get actionPaneConfigurator => _actionPaneConfigurator;
139+
RatioConfigurator? _actionPaneConfigurator;
140+
set actionPaneConfigurator(RatioConfigurator? value) {
141+
if (_actionPaneConfigurator != value) {
142+
_actionPaneConfigurator = value;
143+
if (_replayEndGesture && value != null) {
144+
_replayEndGesture = false;
145+
value.handleEndGestureChanged();
146+
}
147+
}
148+
}
149+
150+
bool _replayEndGesture = false;
136151

137152
/// The value of the ratio over time.
138153
Animation<double> get animation => _animationController.view;
@@ -194,6 +209,12 @@ class SlidableController {
194209
} else {
195210
endGesture.value = ClosingGesture(velocity.abs());
196211
}
212+
213+
// If the movement is too fast, the actionPaneConfigurator may still be
214+
// null. So we have to replay the end gesture when it will not be null.
215+
if (actionPaneConfigurator == null) {
216+
_replayEndGesture = true;
217+
}
197218
}
198219

199220
/// Closes the [Slidable].

test/action_pane_motions_test.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,15 @@ Future<void> testMotion({
127127
),
128128
);
129129

130-
await tester.drag(findSlidable, drag);
131-
await tester.pumpAndSettle();
130+
await tester.dragAndHold(findSlidable, drag);
132131

133132
double centerKey1 = centers[0];
134133
double centerKey2 = centers[1];
135134

136135
expect(getCenter(findKey1), moreOrLessEquals(centerKey1));
137136
expect(getCenter(findKey2), moreOrLessEquals(centerKey2));
138137

139-
await tester.drag(findSlidable, drag);
140-
await tester.pumpAndSettle();
138+
await tester.dragAndHold(findSlidable, drag);
141139

142140
centerKey1 = 12.5;
143141
centerKey2 = 62.5;
@@ -150,3 +148,11 @@ Future<void> testMotion({
150148
expect(getCenter(findKey1), moreOrLessEquals(centerKey1));
151149
expect(getCenter(findKey2), moreOrLessEquals(centerKey2));
152150
}
151+
152+
extension on WidgetTester {
153+
Future<void> dragAndHold(Finder finder, Offset offset) async {
154+
final gesture = await startGesture(getCenter(finder));
155+
await gesture.moveBy(offset);
156+
await pump();
157+
}
158+
}

0 commit comments

Comments
 (0)