0
Q:

get position of a widget in screen flutter

extension GlobalKeyEx on GlobalKey {
  Rect get globalPaintBounds {
    final renderObject = currentContext?.findRenderObject();
    var translation = renderObject?.getTransformTo(null)?.getTranslation();
    if (translation != null && renderObject.paintBounds != null) {
      return renderObject.paintBounds
          .shift(Offset(translation.x, translation.y));
    } else {
      return null;
    }
  }
}
3
@override  void initState() {    WidgetsBinding.instance.addPostFrameCallback(_afterLayout);    super.initState();  } _afterLayout(_) {    _getSizes();    _getPositions();  }
0
//creating Key for red panelGlobalKey _keyRed = GlobalKey();...//set key    Flexible(             flex: 2,             child: Container(               key: _keyRed,               color: Colors.red,             ),     ),
0

New to Communities?

Join the community