getLocationOnScreen static method
Implementation
static Future<void> getLocationOnScreen(
RenderViewModel viewModel, VoltronArray array, Promise? promise) async {
if (promise == null) {
return;
}
var rootViewModel = viewModel.context.rootViewModelMap[viewModel.rootId];
var renderObject =
viewModel.currentContext?.findRenderObject() as RenderBox?;
var rootRenderObject =
rootViewModel?.currentContext?.findRenderObject() as RenderBox?;
var x = 0.0;
var y = 0.0;
var width = 0.0;
var height = 0.0;
if (renderObject == null || rootRenderObject == null) {
promise.reject("this view or root view is null");
} else {
var rootPosition = rootRenderObject.localToGlobal(Offset.zero);
var rootX = rootPosition.dx;
var rootY = rootPosition.dy;
var position = renderObject.localToGlobal(Offset.zero);
var size = renderObject.size;
x = position.dx - rootX;
y = position.dy - rootY;
width = size.width;
height = size.height;
}
final resultMap = VoltronMap();
resultMap.push(kXOnScreen, x.toInt());
resultMap.push(kYOnScreen, y.toInt());
resultMap.push(kViewWidth, width.toInt());
resultMap.push(kViewHeight, height.toInt());
promise.resolve(resultMap);
}