From 28ff8fe9d14db6896a801dd9c28861fac6ce7cf5 Mon Sep 17 00:00:00 2001 From: userFortyTwo Date: Tue, 24 Feb 2026 20:33:22 +0100 Subject: [PATCH 1/3] Fix popover positioning (#103, deleted) Generated by Claude Sonnet v4.5 https://github.com/minikin/popover/issues/103 (deleted) --- lib/src/popover_position_render_object.dart | 46 ++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/src/popover_position_render_object.dart b/lib/src/popover_position_render_object.dart index 00e2cd0..b5ea2c8 100644 --- a/lib/src/popover_position_render_object.dart +++ b/lib/src/popover_position_render_object.dart @@ -50,8 +50,7 @@ final class PopoverPositionRenderObject extends RenderShiftedBox { direction, ); - if (_direction == PopoverDirection.top || - _direction == PopoverDirection.bottom) { + if (_direction == PopoverDirection.top || _direction == PopoverDirection.bottom) { return _dxOffset(_direction, _horizontalOffset(size), size); } else { return _dyOffset(_direction, _verticalOffset(size), size); @@ -95,30 +94,47 @@ final class PopoverPositionRenderObject extends RenderShiftedBox { double _horizontalOffset(Size size) { var offset = 0.0; + const horizontalMargin = 8.0; // Proper horizontal margin instead of arrowHeight - if (attachRect.left > size.width / 2 && - PopoverUtils.physicalSize.width - attachRect.right > size.width / 2) { - offset = attachRect.left + attachRect.width / 2 - size.width / 2; - } else if (attachRect.left < size.width / 2) { - offset = arrowHeight; + // Always try to center the popover first + final centeredOffset = attachRect.left + attachRect.width / 2 - size.width / 2; + + // Check if centered popover would fit on screen with margins + if (centeredOffset >= horizontalMargin && + centeredOffset + size.width <= PopoverUtils.physicalSize.width - horizontalMargin) { + // Perfect centering case + offset = centeredOffset; + } else if (centeredOffset < horizontalMargin) { + // Popover would go off left edge, align to left margin + offset = horizontalMargin; } else { - offset = PopoverUtils.physicalSize.width - arrowHeight - size.width; + // Popover would go off right edge, align to right margin + offset = PopoverUtils.physicalSize.width - horizontalMargin - size.width; } + return offset; } double _verticalOffset(Size size) { var offset = 0.0; + const verticalMargin = 8.0; // Proper vertical margin - if (attachRect.top > size.height / 2 && - PopoverUtils.physicalSize.height - attachRect.bottom > - size.height / 2) { - offset = attachRect.top + attachRect.height / 2 - size.height / 2; - } else if (attachRect.top < size.height / 2) { - offset = arrowHeight; + // Always try to center the popover first + final centeredOffset = attachRect.top + attachRect.height / 2 - size.height / 2; + + // Check if centered popover would fit on screen with margins + if (centeredOffset >= verticalMargin && + centeredOffset + size.height <= PopoverUtils.physicalSize.height - verticalMargin) { + // Perfect centering case + offset = centeredOffset; + } else if (centeredOffset < verticalMargin) { + // Popover would go off top edge, align to top margin + offset = verticalMargin; } else { - offset = PopoverUtils.physicalSize.height - arrowHeight - size.height; + // Popover would go off bottom edge, align to bottom margin + offset = PopoverUtils.physicalSize.height - verticalMargin - size.height; } + return offset; } } From 851f4d6cc76cc93f3e378b2f2cae92ed5508ac0a Mon Sep 17 00:00:00 2001 From: userFortyTwo Date: Sun, 29 Mar 2026 21:42:17 +0200 Subject: [PATCH 2/3] Remove comments and fix indentation (#103, #111) --- lib/src/popover_position_render_object.dart | 38 +++++++++------------ 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/src/popover_position_render_object.dart b/lib/src/popover_position_render_object.dart index b5ea2c8..eec2dc1 100644 --- a/lib/src/popover_position_render_object.dart +++ b/lib/src/popover_position_render_object.dart @@ -94,22 +94,19 @@ final class PopoverPositionRenderObject extends RenderShiftedBox { double _horizontalOffset(Size size) { var offset = 0.0; - const horizontalMargin = 8.0; // Proper horizontal margin instead of arrowHeight + const horizontalMargin = 8.0; - // Always try to center the popover first - final centeredOffset = attachRect.left + attachRect.width / 2 - size.width / 2; + final centeredOffset = + attachRect.left + attachRect.width / 2 - size.width / 2; - // Check if centered popover would fit on screen with margins if (centeredOffset >= horizontalMargin && - centeredOffset + size.width <= PopoverUtils.physicalSize.width - horizontalMargin) { - // Perfect centering case - offset = centeredOffset; + centeredOffset + size.width <= + PopoverUtils.physicalSize.width - horizontalMargin) { + offset = centeredOffset; } else if (centeredOffset < horizontalMargin) { - // Popover would go off left edge, align to left margin - offset = horizontalMargin; + offset = horizontalMargin; } else { - // Popover would go off right edge, align to right margin - offset = PopoverUtils.physicalSize.width - horizontalMargin - size.width; + offset = PopoverUtils.physicalSize.width - horizontalMargin - size.width; } return offset; @@ -117,22 +114,19 @@ final class PopoverPositionRenderObject extends RenderShiftedBox { double _verticalOffset(Size size) { var offset = 0.0; - const verticalMargin = 8.0; // Proper vertical margin + const verticalMargin = 8.0; - // Always try to center the popover first - final centeredOffset = attachRect.top + attachRect.height / 2 - size.height / 2; + final centeredOffset = + attachRect.top + attachRect.height / 2 - size.height / 2; - // Check if centered popover would fit on screen with margins if (centeredOffset >= verticalMargin && - centeredOffset + size.height <= PopoverUtils.physicalSize.height - verticalMargin) { - // Perfect centering case - offset = centeredOffset; + centeredOffset + size.height <= + PopoverUtils.physicalSize.height - verticalMargin) { + offset = centeredOffset; } else if (centeredOffset < verticalMargin) { - // Popover would go off top edge, align to top margin - offset = verticalMargin; + offset = verticalMargin; } else { - // Popover would go off bottom edge, align to bottom margin - offset = PopoverUtils.physicalSize.height - verticalMargin - size.height; + offset = PopoverUtils.physicalSize.height - verticalMargin - size.height; } return offset; From 0fe4e46a130a23e93d52a82287f73c42b8b09735 Mon Sep 17 00:00:00 2001 From: userFortyTwo Date: Fri, 3 Apr 2026 13:36:32 +0200 Subject: [PATCH 3/3] Format popover_position_render_object.dart --- lib/src/popover_position_render_object.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/popover_position_render_object.dart b/lib/src/popover_position_render_object.dart index eec2dc1..d3db846 100644 --- a/lib/src/popover_position_render_object.dart +++ b/lib/src/popover_position_render_object.dart @@ -50,7 +50,8 @@ final class PopoverPositionRenderObject extends RenderShiftedBox { direction, ); - if (_direction == PopoverDirection.top || _direction == PopoverDirection.bottom) { + if (_direction == PopoverDirection.top || + _direction == PopoverDirection.bottom) { return _dxOffset(_direction, _horizontalOffset(size), size); } else { return _dyOffset(_direction, _verticalOffset(size), size);