Only schedule callback when there is mouse (#46113)
This commit is contained in:
parent
fb69a393b8
commit
f8027a795d
@ -502,6 +502,8 @@ class MouseTracker extends ChangeNotifier {
|
|||||||
void schedulePostFrameCheck() {
|
void schedulePostFrameCheck() {
|
||||||
assert(_duringBuildPhase);
|
assert(_duringBuildPhase);
|
||||||
assert(!_duringDeviceUpdate);
|
assert(!_duringDeviceUpdate);
|
||||||
|
if (!mouseIsConnected)
|
||||||
|
return;
|
||||||
if (!_hasScheduledPostFrameCheck) {
|
if (!_hasScheduledPostFrameCheck) {
|
||||||
_hasScheduledPostFrameCheck = true;
|
_hasScheduledPostFrameCheck = true;
|
||||||
SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
|
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', () {
|
test('should not flip out if not all mouse events are listened to', () {
|
||||||
bool isInHitRegionOne = true;
|
bool isInHitRegionOne = true;
|
||||||
bool isInHitRegionTwo = false;
|
bool isInHitRegionTwo = false;
|
||||||
@ -782,12 +803,13 @@ ui.PointerData _pointerData(
|
|||||||
PointerChange change,
|
PointerChange change,
|
||||||
Offset logicalPosition, {
|
Offset logicalPosition, {
|
||||||
int device = 0,
|
int device = 0,
|
||||||
|
PointerDeviceKind kind = PointerDeviceKind.mouse,
|
||||||
}) {
|
}) {
|
||||||
return ui.PointerData(
|
return ui.PointerData(
|
||||||
change: change,
|
change: change,
|
||||||
physicalX: logicalPosition.dx * ui.window.devicePixelRatio,
|
physicalX: logicalPosition.dx * ui.window.devicePixelRatio,
|
||||||
physicalY: logicalPosition.dy * ui.window.devicePixelRatio,
|
physicalY: logicalPosition.dy * ui.window.devicePixelRatio,
|
||||||
kind: PointerDeviceKind.mouse,
|
kind: kind,
|
||||||
device: device,
|
device: device,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user