Commit f8027a79 authored by Tong Mu's avatar Tong Mu Committed by Flutter GitHub Bot

Only schedule callback when there is mouse (#46113)

parent fb69a393
......@@ -502,6 +502,8 @@ class MouseTracker extends ChangeNotifier {
void schedulePostFrameCheck() {
assert(_duringBuildPhase);
assert(!_duringDeviceUpdate);
if (!mouseIsConnected)
return;
if (!_hasScheduledPostFrameCheck) {
_hasScheduledPostFrameCheck = true;
SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
......
......@@ -591,6 +591,27 @@ void main() {
]));
});
test('should not schedule postframe callbacks when no mouse is connected', () {
const MouseTrackerAnnotation annotation = MouseTrackerAnnotation();
_setUpMouseAnnotationFinder((Offset position) sync* {
});
// This device only supports touching
ui.window.onPointerDataPacket(ui.PointerDataPacket(data: <ui.PointerData>[
_pointerData(PointerChange.add, const Offset(0.0, 100.0), kind: PointerDeviceKind.touch),
]));
expect(_mouseTracker.mouseIsConnected, isFalse);
// Attaching an annotation just in case
_mouseTracker.attachAnnotation(annotation);
expect(_binding.postFrameCallbacks, hasLength(0));
_binding.scheduleMouseTrackerPostFrameCheck();
expect(_binding.postFrameCallbacks, hasLength(0));
_mouseTracker.detachAnnotation(annotation);
});
test('should not flip out if not all mouse events are listened to', () {
bool isInHitRegionOne = true;
bool isInHitRegionTwo = false;
......@@ -782,12 +803,13 @@ ui.PointerData _pointerData(
PointerChange change,
Offset logicalPosition, {
int device = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,
}) {
return ui.PointerData(
change: change,
physicalX: logicalPosition.dx * ui.window.devicePixelRatio,
physicalY: logicalPosition.dy * ui.window.devicePixelRatio,
kind: PointerDeviceKind.mouse,
kind: kind,
device: device,
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment