可以参考
https://stackoverflow.com/a/58788092/6112848
```dart
extension GlobalKeyExtension on GlobalKey {
Rect? get globalPaintBounds {
final renderObject = currentContext?.findRenderObject();
final translation = renderObject?.getTransformTo(null).getTranslation();
if (translation != null && renderObject?.paintBounds != null) {
final offset = Offset(translation.x, translation.y);
return renderObject!.paintBounds.shift(offset);
} else {
return null;
}
}
}
```
用法
```
final containerKey = GlobalKey();
Container(
key: containerKey,
width: 100,
height: 50,
)
void printWidgetPosition() {
print('absolute coordinates on screen: ${containerKey.globalPaintBounds}');
}
```
flutter 中获取控件位置在项目中需要在控件渲染之后获取控件的坐标位置