Fix onExit calling when the mouse is removed. (#33477)
This PR solves two problems: currently, the onExit is called for a mouse pointer the moment the removal message is received, except that by the time it actually calls it, there is no _lastEvent for it in the mouse tracker (it's already been removed), resulting in an event being passed to the onExit that contains nulls for the position. Also, removePointer events don't actually get created with a position, although they easily could be, so that even the the _lastEvent in the mouse tracker were still populated, it would still give a null position and delta. This PR adds support for the position and delta in a PointerRemovedEvent, and populates them. In addition, when a remove event is received, it doesn't actually remove the pointer until the mouse position check that gets scheduled actually happens.
This commit is contained in:
@@ -209,35 +209,36 @@ class TestPointer {
|
||||
///
|
||||
/// By default, the time stamp on the event is [Duration.zero]. You can give a
|
||||
/// specific time stamp by passing the `timeStamp` argument.
|
||||
///
|
||||
/// [isDown] must be false, since hover events can't be sent when the pointer
|
||||
/// is up.
|
||||
PointerAddedEvent addPointer({
|
||||
Duration timeStamp = Duration.zero,
|
||||
Offset location,
|
||||
}) {
|
||||
assert(timeStamp != null);
|
||||
_location = location ?? _location;
|
||||
return PointerAddedEvent(
|
||||
timeStamp: timeStamp,
|
||||
kind: kind,
|
||||
device: _device,
|
||||
position: _location ?? Offset.zero,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a [PointerRemovedEvent] with the kind the pointer was created with.
|
||||
/// Create a [PointerRemovedEvent] with the [PointerDeviceKind] the pointer
|
||||
/// was created with.
|
||||
///
|
||||
/// By default, the time stamp on the event is [Duration.zero]. You can give a
|
||||
/// specific time stamp by passing the `timeStamp` argument.
|
||||
///
|
||||
/// [isDown] must be false, since hover events can't be sent when the pointer
|
||||
/// is up.
|
||||
PointerRemovedEvent removePointer({
|
||||
Duration timeStamp = Duration.zero,
|
||||
Offset location,
|
||||
}) {
|
||||
assert(timeStamp != null);
|
||||
_location = location ?? _location;
|
||||
return PointerRemovedEvent(
|
||||
timeStamp: timeStamp,
|
||||
kind: kind,
|
||||
device: _device,
|
||||
position: _location ?? Offset.zero,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -374,14 +375,14 @@ class TestGesture {
|
||||
/// In a test, send a pointer add event for this pointer.
|
||||
Future<void> addPointer({ Duration timeStamp = Duration.zero }) {
|
||||
return TestAsyncUtils.guard<void>(() {
|
||||
return _dispatcher(_pointer.addPointer(timeStamp: timeStamp), null);
|
||||
return _dispatcher(_pointer.addPointer(timeStamp: timeStamp, location: _pointer.location), null);
|
||||
});
|
||||
}
|
||||
|
||||
/// In a test, send a pointer remove event for this pointer.
|
||||
Future<void> removePointer({ Duration timeStamp = Duration.zero }) {
|
||||
Future<void> removePointer({ Duration timeStamp = Duration.zero}) {
|
||||
return TestAsyncUtils.guard<void>(() {
|
||||
return _dispatcher(_pointer.removePointer(timeStamp: timeStamp), null);
|
||||
return _dispatcher(_pointer.removePointer(timeStamp: timeStamp, location: _pointer.location), null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user