Skip to content

Fix overlay not clearing properly + add overlay size parameters#88

Open
nico-sv wants to merge 2 commits into
Shrutimahajan:masterfrom
nico-sv:fix/overlays-not-clearing-properly
Open

Fix overlay not clearing properly + add overlay size parameters#88
nico-sv wants to merge 2 commits into
Shrutimahajan:masterfrom
nico-sv:fix/overlays-not-clearing-properly

Conversation

@nico-sv

@nico-sv nico-sv commented Mar 18, 2026

Copy link
Copy Markdown

Summary

This PR fixes several bugs related to the suggestions overlay lifecycle in GooglePlaceAutoCompleteTextField, and introduces two new optional parameters overlayWidth and overlayHeight to allow consumers to control the size of the suggestions dropdown.


Changes

Bug Fixes

  • removeOverlay(): Rewrote to properly null out _overlayEntry after removal, preventing stale references and double-remove crashes.
  • textChanged(): Now calls clearData() when the input is empty, instead of attempting to remove a potentially null overlay entry directly.
  • getLocation(): Calls removeOverlay() before inserting a new overlay, preventing duplicate overlays from stacking on top of each other.
  • dispose(): Added proper widget disposal — removes the active overlay and closes the PublishSubject stream when the widget is unmounted.

New Features

  • overlayWidth (optional): Constrains the width of the suggestions overlay. Capped at the text input widget's own width.
  • overlayHeight (optional): Constrains the max height of the suggestions overlay via ConstrainedBox, enabling scrolling when the list exceeds the limit.

Motivation

  • The overlay was not being removed correctly in some scenarios, causing the widget tree to look like this, where each Positioned was a new non-removed overlay, causing performance issues:
image
  • The widget had no dispose() method, leading to memory leaks and potential setState calls after the widget was unmounted.

  • Additionally, consumers had no way to control the size of the suggestions overlay, which made it difficult to integrate the widget in constrained layouts.


Breaking Changes

None - all changes are backwards-compatible.


Testing and Validation

  • Code follows the existing style and conventions
  • Code was tested extensively to maintain current behavior, while fixing the found issues
  • Documentation has been updated
  • CHANGELOG.md has been updated
  • The change is backward compatible

Notes

  • overlayWidth is capped at the widget's own width to avoid layout overflow.
  • The dispose() method closes the PublishSubject stream, which also cancels any pending debounced events — no additional stream management is needed.
  • No breaking changes to the public API; all new parameters are optional and default to previous behavior.

@nico-sv

nico-sv commented Mar 18, 2026

Copy link
Copy Markdown
Author

@shruti-techindustan / @Shrutimahajan this PR fixes a pretty nasty performance issue bug, and the new optional params would greatly improve user experience while being backwards compatible.

Would appreciate if you could take a look and merge if you like the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant