getRect method

Rect getRect()

Implementation

Rect getRect() {
  final box = key!.currentContext!.findRenderObject() as RenderBox;

  var boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
  if (boxOffset.dx.isNaN || boxOffset.dy.isNaN) {
    return const Rect.fromLTRB(0, 0, 0, 0);
  }
  final topLeft = box.size.topLeft(boxOffset);
  final bottomRight = box.size.bottomRight(boxOffset);

  final rect = Rect.fromLTRB(
    topLeft.dx - padding.left < 0 ? 0 : topLeft.dx - padding.left,
    topLeft.dy - padding.top < 0 ? 0 : topLeft.dy - padding.top,
    bottomRight.dx + padding.right > screenWidth!
        ? screenWidth!
        : bottomRight.dx + padding.right,
    bottomRight.dy + padding.bottom > screenHeight!
        ? screenHeight!
        : bottomRight.dy + padding.bottom,
  );
  return rect;
}