ListVisualisation.enlargement constructor

ListVisualisation.enlargement({
  1. double horizontalMultiplier = 1.5,
  2. double verticalMultiplier = 1.5,
})

Enlarges items in an SnappyListView when they are the current page. The multiplication can be configured in vertical and horizontal percentage. If no enlargement in one direction is wished the it should equal 1.

Implementation

ListVisualisation.enlargement({
  double horizontalMultiplier = 1.5,
  double verticalMultiplier = 1.5,
}) : _parameters = ((item) {
        //A linear function [0, 0.5] that has a y-axis intersection at 1 and
        // intersects point (0.5 | enlargementMultiplier), therefore having a
        //gradient of g = (m-1)/0.5
        double f(double multiplier) =>
            ((multiplier - 1) / 0.5) * (0.5 - item.pageDifference.abs()) + 1;
        double translationOf(double multiplier) =>
            -((item.itemSize ?? 1) * f(multiplier) - (item.itemSize ?? 1)) /
            2;
        return ListVisualisationParameters(
          transform: Matrix4Transform()
              .scaleBy(
                x: item.isCurrent ? f(horizontalMultiplier) : 1,
                y: item.isCurrent ? f(verticalMultiplier) : 1,
              )
              .translate(
                x: item.isCurrent ? translationOf(horizontalMultiplier) : 0,
                y: item.isCurrent ? translationOf(verticalMultiplier) : 0,
              )
              .matrix4,
          curve: Curves.linear,
          duration: const Duration(milliseconds: 0),
        );
      });