Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 499e900

Browse files
authored
Fix timer keeps active when resampling disabled in some cases (#97197)
1 parent 3669e36 commit 499e900

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/flutter/lib/src/gestures/binding.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class _Resampler {
180180
}
181181
_resamplers.clear();
182182
_frameTime = Duration.zero;
183+
_timer?.cancel();
183184
}
184185

185186
void _onSampleTimeChanged() {

packages/flutter/test/gestures/gesture_binding_resample_event_on_widget_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,20 @@ void main() {
123123
expect(events[3].timeStamp, currentTestFrameTime() + kSamplingOffset);
124124
expect(events[3], isA<PointerUpEvent>());
125125
});
126+
127+
testWidgets('Timer should be canceled when resampling stopped', (WidgetTester tester) async {
128+
// A timer will be started when event's timeStamp is larger than sampleTime.
129+
final ui.PointerDataPacket packet = ui.PointerDataPacket(
130+
data: <ui.PointerData>[
131+
ui.PointerData(
132+
timeStamp: Duration(microseconds: DateTime.now().microsecondsSinceEpoch),
133+
),
134+
],
135+
);
136+
GestureBinding.instance.resamplingEnabled = true;
137+
ui.window.onPointerDataPacket!(packet);
138+
139+
// Expected to stop resampling, but the timer keeps active if _timer?.cancel() not be called.
140+
GestureBinding.instance.resamplingEnabled = false;
141+
});
126142
}

0 commit comments

Comments
 (0)