onScaleUpdate method

  1. @mustCallSuper
void onScaleUpdate(
  1. ScaleUpdateEvent event
)

Called continuously as the user updates the scale gesture.

Implementation

@mustCallSuper
void onScaleUpdate(ScaleUpdateEvent event) {
  final updated = <TaggedComponent<ScaleCallbacks>>{};
  final stale = <TaggedComponent<ScaleCallbacks>>{};

  // Deliver to components under the pointer
  event.deliverAtPoint(
    rootComponent: game,
    deliverToAll: true,
    eventHandler: (ScaleCallbacks component) {
      final record = TaggedComponent(event.pointerId, component);
      if (_scaleRecords.contains(record)) {
        if (!component.isMounted || component.isRemoving) {
          stale.add(record);
        } else {
          component.onScaleUpdate(event);
          updated.add(record);
        }
      }
    },
  );

  // Also deliver to components that started the scale but weren't under
  // the pointer this frame
  // Currently, the id passed to the scale
  // events is always 0, so maybe it's not relevant.
  for (final record in _scaleRecords) {
    if (record.pointerId != event.pointerId) {
      continue;
    }
    final component = record.component;
    if (!component.isMounted || component.isRemoving) {
      stale.add(record);
      continue;
    }
    if (!updated.contains(record)) {
      record.component.onScaleUpdate(event);
    }
  }

  if (stale.isNotEmpty) {
    final endEvent = ScaleEndEvent(event.pointerId, ScaleEndDetails());
    for (final record in stale) {
      record.component.onScaleEnd(endEvent);
    }
    _scaleRecords.removeAll(stale);
  }
}