isWithinBounds static method

bool isWithinBounds(
  1. BuildContext element,
  2. Offset position,
  3. double pixRatio,
  4. int screenWidth,
  5. int screenHeight,
)

Implementation

static bool isWithinBounds(BuildContext element, Offset position,
    double pixRatio, int screenWidth, int screenHeight) {
  try {
    int x = ((position.dx * pixRatio)).round();
    int y = ((position.dy * pixRatio)).round();
    int width = ((element.size?.width ?? 0) * pixRatio).round();
    int height = ((element.size?.height ?? 0) * pixRatio).round();
    return x >= 0 &&
        y >= 0 &&
        (x + width) <= screenWidth &&
        (y + height) <= screenHeight &&
        width > 0 &&
        height > 0;
  } catch (e) {
    debugPrint("Error in isWithinBounds: $e");
    return false;
  }
}