update method Null safety

  1. @override
void update(
  1. Offset delta
)
override

Updates the gesture when gesture detection is happening.

Implementation

@override
void update(Offset delta) {
  if (!_triggered) {
    _gestureX += delta.dx;
    _gestureY += delta.dy;
    if ((direction == AxisDirection.left && _gestureX <= -triggerDistance) ||
        (direction == AxisDirection.right && _gestureX >= triggerDistance) ||
        (direction == AxisDirection.up && _gestureY <= -triggerDistance) ||
        (direction == AxisDirection.down && _gestureY >= triggerDistance)) {
      _triggered = true;
      _gestureX = 0;
      _gestureY = 0;
    }

    if (!_triggered) return;
  }

  if (_failed) return;

  _gestureX += delta.dx;
  _gestureY += delta.dy;

  if ((_counterAxis == Axis.horizontal && _gestureX.abs() >= failDistance) ||
      (_counterAxis == Axis.vertical && _gestureY.abs() >= failDistance)) {
    _failed = true;
    return;
  }

  if ((direction == AxisDirection.left && _gestureX < -distance) ||
      (direction == AxisDirection.right && _gestureX > distance) ||
      (direction == AxisDirection.up && _gestureY < -distance) ||
      (direction == AxisDirection.down && _gestureY > distance)) {
    _complete = true;
  }
}