measureInWindow method

void measureInWindow(
  1. RenderViewModel viewModel,
  2. VoltronArray array,
  3. Promise? promise
)

Implementation

void measureInWindow(
  RenderViewModel viewModel,
  VoltronArray array,
  Promise? promise,
) {
  if (promise == null) return;
  var renderObject = viewModel.currentContext?.findRenderObject() as RenderBox?;
  if (renderObject == null) {
    promise.reject("this view is null");
  } else {
    var position = renderObject.localToGlobal(Offset.zero);
    var size = renderObject.size;

    var x = position.dx;
    var y = position.dy;
    var width = size.width;
    var height = size.height;

    var statusBarHeight = ScreenUtil.getInstance().statusBarHeight;
    var navigationBarHeight = ScreenUtil.getInstance().navigationBarHeight;
    // We need to remove the status bar from the height.  getLocationOnScreen will include the
    // status bar.
    if (statusBarHeight > 0) {
      y -= statusBarHeight;
    }

    var paramsMap = VoltronMap();
    paramsMap.push("x", x);
    paramsMap.push("y", y);
    paramsMap.push("width", width);
    paramsMap.push("height", height);
    paramsMap.push("statusBarHeight", statusBarHeight);
    paramsMap.push("navigationBarHeight", navigationBarHeight);
    promise.resolve(paramsMap);
  }
}