getToggleTarget method

double getToggleTarget(
  1. SlideDirection direction,
  2. double ratio,
  3. bool isForward
)

according to direction, ratio and isForward calculate the target ratio when we should continue to slide after dragging ends

Implementation

double getToggleTarget(
    SlideDirection direction, double ratio, bool isForward) {
  if (ratio >= 0 && !hasPreAction) {
    return 0;
  } else if (ratio <= 0 && !hasPostAction) {
    return 0;
  }

  return switch (direction) {
    SlideDirection.leftToRight ||
    SlideDirection.topToBottom =>
      isForward ? 1 : 0,
    SlideDirection.bottomToTop ||
    SlideDirection.rightToLeft =>
      isForward ? -1 : 0,
    SlideDirection.idle => 0,
  };
}