getViewPosition static method
void
getViewPosition()
Implementation
static void getViewPosition(String listenerId, String clientElementId,
double pixelRatio, int screenWidth, int screenHeight) {
BuildContext? element = findViewByKey(clientElementId, _ctx);
if (element != null) {
RenderBox box = element.findRenderObject() as RenderBox;
Offset position = box.localToGlobal(Offset.zero);
if (isWithinBounds(
element, position, pixelRatio, screenWidth, screenHeight)) {
Map<String, int?> positionMap = {
"x": (position.dx * pixelRatio).round(),
"y": (position.dy * pixelRatio).round(),
"width": ((element.size?.width ?? 0) * pixelRatio).round(),
"height": ((element.size?.height ?? 0) * pixelRatio).round()
};
_channel.invokeMethod('getViewPosition', <String, dynamic>{
"listenerId": listenerId,
"position": positionMap
});
return;
}
}
// Passing values which make the object get ignored
Map<String, int?> positionMapDefault = {
"x": -1,
"y": -1,
"width": -1,
"height": -1
};
_channel.invokeMethod('getViewPosition', <String, dynamic>{
"listenerId": listenerId,
"position": positionMapDefault
});
}