percentOffScreen method

double percentOffScreen(
  1. double x,
  2. double shapeDimension,
  3. double screenDimension
)

The percentage of the shape that is off screen.

  • 0.0 means the shape is completely on screen.
  • 0.5 means the shape is halfway off screen.
  • 1.0 means the shape is completely off screen.

shapeDimension is the width or height of the shape depending on the ScrollDirection. Width in the case of horizontal (left/right) scrolling and height in the case of vertical (up/down) scrolling.

screenDimension is the width or height of the screen depending on the ScrollDirection. Width in the case of horizontal (left/right) scrolling and height in the case of vertical (up/down) scrolling.

Implementation

double percentOffScreen(
  double x,
  double shapeDimension,
  double screenDimension,
) {
  late final double amountOffScreen;

  if (x < 0) {
    amountOffScreen = x;
  } else if (x > screenDimension - shapeDimension) {
    amountOffScreen = x - (screenDimension - shapeDimension);
  } else {
    amountOffScreen = 0.0;
  }

  return (amountOffScreen / shapeDimension).abs();
}