Reland "Fix crash from alt-tab'ing just after startup" (#103093)

This commit is contained in:
Tong Mu
2022-05-05 17:44:08 -07:00
committed by GitHub
parent 543cc6032e
commit 55881f7ae6
2 changed files with 12 additions and 1 deletions

View File

@@ -319,7 +319,8 @@ class MouseTracker extends ChangeNotifier {
// so that [mouseIsConnected], which is decided by `_mouseStates`, is
// correct during the callbacks.
if (existingState == null) {
assert(event is! PointerRemovedEvent);
if (event is PointerRemovedEvent)
return;
_mouseStates[device] = _MouseState(initialEvent: event);
} else {
assert(event is! PointerAddedEvent);

View File

@@ -133,6 +133,16 @@ void main() {
listenerLogs.clear();
});
// Regression test for https://github.com/flutter/flutter/issues/90838
test('should not crash if the first event is a Removed event', () {
final List<PointerEvent> events = <PointerEvent>[];
setUpWithOneAnnotation(logEvents: events);
ui.window.onPointerDataPacket!(ui.PointerDataPacket(data: <ui.PointerData>[
_pointerData(PointerChange.remove, Offset.zero),
]));
events.clear();
});
test('should correctly handle multiple devices', () {
final List<PointerEvent> events = <PointerEvent>[];
setUpWithOneAnnotation(logEvents: events);