onDragUpdate method
Called continuously during the drag as the user moves their finger.
The default handler propagates this event to those components who received
the initial onDragStart event. If the position of the pointer is outside
of the bounds of the component, then this event will nevertheless be
delivered, with local coordinates that fall outside those bounds. A
component that hit testing no longer reaches at all -- because an ancestor
started ignoring events, say -- is delivered to from _records instead,
with an empty rendering trace, so its local coordinates are unavailable.
Implementation
@mustCallSuper
void onDragUpdate(DragUpdateEvent event) {
final updated = <TaggedComponent<DragCallbacks>>{};
final stale = <TaggedComponent<DragCallbacks>>{};
event.deliverAtPoint(
rootComponent: gameRef,
deliverToAll: true,
eventHandler: (DragCallbacks component) {
final record = TaggedComponent(event.pointerId, component);
if (_records.contains(record)) {
if (!component.isMounted || component.isRemoving) {
stale.add(record);
} else {
component.onDragUpdate(event);
updated.add(record);
}
}
},
);
for (final record in _records) {
if (record.pointerId != event.pointerId) {
continue;
}
final component = record.component;
if (!component.isMounted || component.isRemoving) {
stale.add(record);
continue;
}
if (!updated.contains(record)) {
component.onDragUpdate(event);
}
}
if (stale.isNotEmpty) {
final cancelEvent = DragCancelEvent(event.pointerId);
for (final record in stale) {
record.component.onDragCancel(cancelEvent);
}
_records.removeAll(stale);
}
}