I’m developing a Flutter app where I use an OverlayEntry to display a dropdown-like widget below a button when it is clicked. However, the content of the overlay has dynamic height based on the items inside. If there’s not enough space below the button, I want the overlay to be positioned above the button instead of expanding off the screen.
The main challenge is dynamically calculating the space above and below the button and deciding whether the overlay should go above or below based on the available space. I’ve already used RenderBox to get the button’s position and size, but I’m having trouble efficiently positioning the overlay when the height of the overlay is dynamic.
Below the Button: The overlay should appear below the button if there is enough space.
Above the Button: If there is not enough space below, the overlay should appear above the button.
The overlay should dynamically adjust its height to fit within the available space without overflowing the screen.
2
Answers
To solve your problem, I would have divided it into four steps:
Hope this helps you.
Here is an example of code that you should adapt to your environment