calculateScale method

double calculateScale(
  1. int index
)

Calculate scale transformation for dynamic item size

Implementation

double calculateScale(int index) {
  //scroll-pixel position for index to be at the center of ScrollSnapList
  double intendedPixel = index * widget.itemSize;
  double difference = intendedPixel - currentPixel;

  if (widget.dynamicSizeEquation != null) {
    //force to be >= 0
    double scale = widget.dynamicSizeEquation!(difference);
    return scale < 0 ? 0 : scale;
  }

  //default equation
  return 1 - min(difference.abs() / 500, 0.4);
}