measure method

int measure(
  1. int instanceId,
  2. int nodeId,
  3. FlexLayoutParams layoutParams
)

Implementation

int measure(int instanceId, int nodeId, FlexLayoutParams layoutParams) {
  TextPainter? painter;
  var exception = false;

  var virtualNode = _virtualNodes[nodeId];
  if (virtualNode is TextVirtualNode) {
    try {
      painter = virtualNode.createPainter(
        layoutParams.width,
        layoutParams.widthMode,
      );
    } catch (e) {
      LogUtils.dRenderNode('ID:$nodeId, calculate layout error, error:${e.toString()}');
      exception = true;
    }
  }

  if (exception || painter == null) {
    return FlexOutput.makeMeasureResult(
      layoutParams.width,
      layoutParams.height,
    );
  } else {
    LogUtils.dRenderNode(
      'ID:$nodeId, calculate layout success, width:${painter.width}, height:${painter.height}',
    );
    return FlexOutput.makeMeasureResult(dpToPx(painter.width), dpToPx(painter.height));
  }
}