overlay_container icon indicating copy to clipboard operation
overlay_container copied to clipboard

TextField inside Overlay

Open igala opened this issue 4 years ago • 1 comments

Adding TextField and when focusing rebuilds the overlay and looses focus. Any idea how to fix this?

igala avatar Oct 22 '20 14:10 igala

Hi @igala!

Thanks for raising this issue. If I had to suggest something right now I would suggest this fix. Steps to follow: • Fork this repo.

• Inside the file https://github.com/MustansirZia/overlay_container/blob/master/lib/overlay_container.dart change the _show method to this.


 void _show() {
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      await Future.delayed(Duration(milliseconds: 280));
        if (_overlayEntry == null) {
           _overlayEntry = _buildOverlayEntry();
           Overlay.of(context).insert(_overlayEntry);
        } else {
           _overlayEntry.markNeedsBuild();
        }
        _opened = true;
    });
  }

and the _hide method to this.

  void _hide() {
    if (_opened) {
      WidgetsBinding.instance.addPostFrameCallback((_) {
        _overlayEntry.remove();
        _overlayEntry = null;
        _opened = false;
      });
    }
  }

• Install the fork instead of the original library as shown for this example.

Screenshot 2020-10-23 at 3 50 41 PM

This will in turn not rebuild the overlay from scratch like the way it's doing right now. Let me know how it goes! :)

MustansirZia avatar Oct 23 '20 10:10 MustansirZia