Flutter, How to get the size of a widget?
In the link you referred to, after creating the GlobalKey it is assigned to the red container
but in your code you haven't assigned it to the container so it can be referred to from the _getSizes() and _getPositions(), _keyRed have to be attached to a Context in your code before you use it.
//creating Key for red panelGlobalKey _keyRed = GlobalKey(); ... //set key Flexible( flex: 2, child: Container( key: _keyRed, // assigned as a key of the red container. color: Colors.red, ), ),