getViewPositionInWeb static method
Implementation
static JSObject getViewPositionInWeb(String clientElementId,
double pixelRatio, int screenWidth, int screenHeight) {
try {
screenHeight = (MediaQuery.of(ctx).size.height * pixelRatio).round();
screenWidth = (MediaQuery.of(ctx).size.width * pixelRatio).round();
BuildContext? element = findViewByKey(clientElementId, ctx);
if (element != null) {
RenderBox box = element.findRenderObject() as RenderBox;
Offset position = box.localToGlobal(Offset.zero);
if (isWithinBoundsOfWeb(element, position, screenWidth, screenHeight) &&
visibilityMap[clientElementId] == 100.0) {
int x = (position.dx).round();
int y = (position.dy).round();
int width = (element.size?.width ?? 0).round();
int height = (element.size?.height ?? 0).round();
int left = (position.dx).round();
int top = (position.dy).round();
int right = x + width;
int bottom = y + height;
// Create a JavaScript object directly and cast to JSObject
return ({
'x': x,
'y': y,
'width': width,
'height': height,
'left': left,
'top': top,
'right': right,
'bottom': bottom
}.jsify() as JSObject);
}
}
} catch (e) {
debugPrint("Error in getViewPosition: $e");
}
// Return default values as a JS object
return ({
'x': -1,
'y': -1,
'width': -1,
'height': -1,
'left': -1,
'top': -1,
'right': -1,
'bottom': -1
}.jsify() as JSObject);
}