diff --git a/packages/flutter/lib/src/gestures/mouse_tracking.dart b/packages/flutter/lib/src/gestures/mouse_tracking.dart index 3e97dcff28..9c3596100d 100644 --- a/packages/flutter/lib/src/gestures/mouse_tracking.dart +++ b/packages/flutter/lib/src/gestures/mouse_tracking.dart @@ -131,8 +131,8 @@ class MouseTracker extends ChangeNotifier { /// Stops tracking an annotation, indicating that it has been removed from the /// layer tree. /// - /// If the associated layer is not removed, and receives a hit, then - /// [sendMouseNotifications] will assert the next time it is called. + /// An assertion error will be thrown if the associated layer is not removed + /// and receives another mouse hit. void detachAnnotation(MouseTrackerAnnotation annotation) { final _TrackedAnnotation trackedAnnotation = _findAnnotation(annotation); for (int deviceId in trackedAnnotation.activeDevices) { @@ -155,7 +155,7 @@ class MouseTracker extends ChangeNotifier { if (_trackedAnnotations.isNotEmpty && !_scheduledPostFramePositionCheck) { _scheduledPostFramePositionCheck = true; SchedulerBinding.instance.addPostFrameCallback((Duration duration) { - sendMouseNotifications(_lastMouseEvent.keys); + _sendMouseNotifications(_lastMouseEvent.keys); _scheduledPostFramePositionCheck = false; }); } @@ -171,14 +171,14 @@ class MouseTracker extends ChangeNotifier { // If we are adding the device again, then we're not removing it anymore. _pendingRemovals.remove(deviceId); _addMouseEvent(deviceId, event); - sendMouseNotifications({deviceId}); + _sendMouseNotifications({deviceId}); return; } if (event is PointerRemovedEvent) { _removeMouseEvent(deviceId, event); // If the mouse was removed, then we need to schedule one more check to // exit any annotations that were active. - sendMouseNotifications({deviceId}); + _sendMouseNotifications({deviceId}); } else { if (event is PointerMoveEvent || event is PointerHoverEvent || event is PointerDownEvent) { final PointerEvent lastEvent = _lastMouseEvent[deviceId]; @@ -187,7 +187,7 @@ class MouseTracker extends ChangeNotifier { lastEvent is PointerAddedEvent || lastEvent.position != event.position) { // Only schedule a frame if we have our first event, or if the // location of the mouse has changed, and only if there are tracked annotations. - sendMouseNotifications({deviceId}); + _sendMouseNotifications({deviceId}); } } } @@ -212,17 +212,13 @@ class MouseTracker extends ChangeNotifier { return _trackedAnnotations.containsKey(annotation); } - /// Tells interested objects that a mouse has entered, exited, or moved, given - /// a callback to fetch the [MouseTrackerAnnotation] associated with a global - /// offset. - /// - /// This is called from a post-frame callback when the layer tree has been - /// updated, right after rendering the frame. - /// - /// This function is only public to allow for proper testing of the - /// MouseTracker. Do not call in other contexts. - @visibleForTesting - void sendMouseNotifications(Iterable deviceIds) { + // Tells interested objects that a mouse has entered, exited, or moved, given + // a callback to fetch the [MouseTrackerAnnotation] associated with a global + // offset. + // + // This is called from a post-frame callback when the layer tree has been + // updated, right after rendering the frame. + void _sendMouseNotifications(Iterable deviceIds) { if (_trackedAnnotations.isEmpty) { return; } diff --git a/packages/flutter/test/gestures/mouse_tracking_test.dart b/packages/flutter/test/gestures/mouse_tracking_test.dart index 7daa8a96fe..6987010452 100644 --- a/packages/flutter/test/gestures/mouse_tracking_test.dart +++ b/packages/flutter/test/gestures/mouse_tracking_test.dart @@ -93,7 +93,6 @@ void main() { _pointerData(PointerChange.hover, const Offset(1.0, 401.0), device: 1), ]); RendererBinding.instance.mouseTracker.attachAnnotation(annotation); - RendererBinding.instance.mouseTracker.sendMouseNotifications({0}); isInHitRegionOne = true; ui.window.onPointerDataPacket(packet1); expect(events, _equalToEventsOnCriticalFields([ @@ -124,11 +123,9 @@ void main() { // add in a second mouse simultaneously. clear(); ui.window.onPointerDataPacket(packet5); - RendererBinding.instance.mouseTracker.sendMouseNotifications({1}); expect(events, _equalToEventsOnCriticalFields([ const PointerEnterEvent(position: Offset(1.0, 401.0), device: 1), const PointerHoverEvent(position: Offset(1.0, 401.0), device: 1), - const PointerHoverEvent(position: Offset(1.0, 401.0), device: 1), ])); }); @@ -142,7 +139,6 @@ void main() { ]); isInHitRegionOne = true; RendererBinding.instance.mouseTracker.attachAnnotation(annotation); - RendererBinding.instance.mouseTracker.sendMouseNotifications({0}); ui.window.onPointerDataPacket(packet1); @@ -196,7 +192,6 @@ void main() { ]); isInHitRegionOne = true; RendererBinding.instance.mouseTracker.attachAnnotation(annotation); - RendererBinding.instance.mouseTracker.sendMouseNotifications({0}); ui.window.onPointerDataPacket(packet1); ui.window.onPointerDataPacket(packet2); expect(events, _equalToEventsOnCriticalFields([ @@ -219,7 +214,6 @@ void main() { ]); isInHitRegionOne = true; RendererBinding.instance.mouseTracker.attachAnnotation(annotation); - RendererBinding.instance.mouseTracker.sendMouseNotifications({0}); ui.window.onPointerDataPacket(packet1); ui.window.onPointerDataPacket(packet2); expect(events, _equalToEventsOnCriticalFields([