slide method

FSliderHaptic? slide(
  1. double offset, {
  2. required bool min,
  3. double velocity = 0,
})

Slides the active track to the given offset on the min edge, in logical pixels.

The delta is relative to the origin defined by FSlider.layout. velocity is the absolute per-frame drag delta in pixels; it gates the FSliderHaptic.collision event via hapticFeedbackVelocity.

Returns the haptic type the caller should fire, or null when no haptic should fire.

Implementation

FSliderHaptic? slide(double offset, {required bool min, double velocity = 0}) {
  if (interaction == .tap) {
    return null;
  }

  assert(min ? active.min : active.max, 'Slider is not extendable at the ${min ? 'min' : 'max'} edge.');
  if (_value case final old? when old != (value = old.move(min: min, to: offset))) {
    final range = value.pixels.max - value.pixels.min;
    final oldRange = old.pixels.max - old.pixels.min;

    final minBound = value.pixels.min == 0 && 0 < old.pixels.min;
    final maxBound =
        value.pixels.max == value.pixelConstraints.extent && old.pixels.max < old.pixelConstraints.extent;
    final minRange = range == value.pixelConstraints.min && value.pixelConstraints.min < oldRange;
    final maxRange = range == value.pixelConstraints.max && oldRange < value.pixelConstraints.max;

    if ((minBound || maxBound || minRange || maxRange) && hapticFeedbackVelocity <= velocity.abs()) {
      return .collision;
    }

    final (from, to) = min ? (old.pixels.min, value.pixels.min) : (old.pixels.max, value.pixels.max);
    for (final tick in _ticks) {
      if (_cross(from, tick, to)) {
        return .tick;
      }
    }
  }

  return null;
}