Initialize the key:

  GlobalKey _keyGreen = GlobalKey();
Copy the code

Refer to the Key:

  InkWell(
            child: Container(
              margin: EdgeInsets.only(left: 30),
              child: Text(
                "Key test",
                textAlign: TextAlign.center,
              ),
            ),
            key: _keyGreen,
            onTap: () {
              // Get the current Widget size
              final RenderBox renderBox =
                  _keyGreen.currentContext.findRenderObject();
              final sizeGreen = renderBox.size;
              print("SIZEofgreen: $sizeGreen");

              // Get the current screen position
              final positionGreen = renderBox.localToGlobal(Offset.zero);
              print("POSITIONofgreen: $positionGreen"); },)Copy the code

Get screen position:

final RenderBox renderBox = _keyGreen.currentContext.findRenderObject();
              final positionGreen = renderBox.localToGlobal(Offset.zero);
              print("POSITIONofgreen: $positionGreen");
Copy the code

Get the current Widget size:

final RenderBox renderBox = _keyGreen.currentContext.findRenderObject();
 final sizeGreen = renderBox.size;
print("SIZEofgreen: $sizeGreen");
Copy the code

Note:

Be sure to identify the key