Search code examples
flutterdartsizeoverlay

Flutter OverlayEntry not taking width, height


I am trying to display an OverlayEntry below one of my Textfields.

It is working so far, the only problem is with the OverlayEntry itself, for some reason, whatever width and height I give to the child, the Overlay takes all available screen width, and all the way down to the bottom of the screen in height.

Here some code, where as a sample, im just trying to show a small red square of 100x100...not working:

OverlayEntry _getOverlay() {
    return OverlayEntry(
      builder: (context) => CompositedTransformFollower(
        link: _layerLink,
        showWhenUnlinked: false,
        offset: Offset(0, fieldHeight + 5),
        child: Container(
          width: 100,
          height: 100,
          color: Colors.red,
        ),
      ),
    );
  }

How do I manage the width and height of the OverlayEntry??


Solution

  • not checked, but might be worked.

    use Positioned inside OverlayEntry. check below example.

    return OverlayEntry(
          builder: (context) => Positioned(
            width: 100,
            height: 100,
            child:CompositedTransformFollower(
                 link: this._layerLink,
                 child: Container(
                     color: Colors.red,
                 ),
            ),
          ),
        );