resolve static method
Resolves which index to snap to after a horizontal gesture.
Implementation
static int resolve({
required int currentIndex,
required double velocity,
required double displacement,
required double cardWidth,
required int itemCount,
double velocityThreshold = 600.0,
double distanceThreshold = 0.3,
}) {
if (itemCount <= 1) return 0;
final normalizedDisplacement = displacement / math.max(cardWidth, 1.0);
int targetIndex = currentIndex;
if (velocity.abs() > velocityThreshold) {
targetIndex = velocity > 0 ? currentIndex - 1 : currentIndex + 1;
} else if (normalizedDisplacement.abs() > distanceThreshold) {
targetIndex = normalizedDisplacement > 0
? currentIndex - 1
: currentIndex + 1;
}
return targetIndex.clamp(0, itemCount - 1);
}