handlePointerSignal method

void handlePointerSignal(
  1. PointerSignalEvent event
)

Handles pointer scroll events from the Listener widget

Implementation

void handlePointerSignal(PointerSignalEvent event) {
  if (event is! PointerScrollEvent) return;
  if (!scrollController.hasClients) return;

  // Calculate scroll delta with multiplier and direction
  final scrollDelta = event.scrollDelta.dy * _config.scrollMultiplier;
  final adjustedDelta = _reverse ? -scrollDelta : scrollDelta;

  // Update target position (bounded by scroll extent)
  final maxExtent = scrollController.position.maxScrollExtent;
  final newTarget = (_targetPosition + adjustedDelta).clamp(0.0, maxExtent);

  // Calculate velocity for momentum phase
  final now = DateTime.now();
  if (_lastEventTime != null) {
    final timeDelta = now.difference(_lastEventTime!).inMicroseconds / 1e6;
    if (timeDelta > 0 && timeDelta < 0.1) {
      // Ignore if too much time passed
      // Accumulate velocity with exponential smoothing for natural feel
      final instantVelocity = adjustedDelta / timeDelta;
      _velocity = _velocity * 0.7 + instantVelocity * 0.3;
    }
  } else {
    // First event - set initial velocity
    _velocity = adjustedDelta * 10; // Rough estimate
  }

  _lastEventTime = now;
  _targetPosition = newTarget;

  // Start animation if not already running
  if (!_isAnimating) {
    _currentPosition = scrollController.offset;
    _startAnimation();
  }
}