Fix timer keeps active when resampling disabled in some cases (#97197)
This commit is contained in:
parent
3669e3669a
commit
499e900e39
@ -180,6 +180,7 @@ class _Resampler {
|
|||||||
}
|
}
|
||||||
_resamplers.clear();
|
_resamplers.clear();
|
||||||
_frameTime = Duration.zero;
|
_frameTime = Duration.zero;
|
||||||
|
_timer?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSampleTimeChanged() {
|
void _onSampleTimeChanged() {
|
||||||
|
@ -123,4 +123,20 @@ void main() {
|
|||||||
expect(events[3].timeStamp, currentTestFrameTime() + kSamplingOffset);
|
expect(events[3].timeStamp, currentTestFrameTime() + kSamplingOffset);
|
||||||
expect(events[3], isA<PointerUpEvent>());
|
expect(events[3], isA<PointerUpEvent>());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Timer should be canceled when resampling stopped', (WidgetTester tester) async {
|
||||||
|
// A timer will be started when event's timeStamp is larger than sampleTime.
|
||||||
|
final ui.PointerDataPacket packet = ui.PointerDataPacket(
|
||||||
|
data: <ui.PointerData>[
|
||||||
|
ui.PointerData(
|
||||||
|
timeStamp: Duration(microseconds: DateTime.now().microsecondsSinceEpoch),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
GestureBinding.instance.resamplingEnabled = true;
|
||||||
|
ui.window.onPointerDataPacket!(packet);
|
||||||
|
|
||||||
|
// Expected to stop resampling, but the timer keeps active if _timer?.cancel() not be called.
|
||||||
|
GestureBinding.instance.resamplingEnabled = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user