performLayout method

  1. @override
void performLayout()
override

Do the work of computing the layout for this render object.

Do not call this function directly: call layout instead. This function is called by layout when there is actually work to be done by this render object during layout. The layout constraints provided by your parent are available via the constraints getter.

If sizedByParent is true, then this function should not actually change the dimensions of this render object. Instead, that work should be done by performResize. If sizedByParent is false, then this function should both change the dimensions of this render object and instruct its children to layout.

In implementing this function, you must call layout on each of your children, passing true for parentUsesSize if your layout information is dependent on your child's layout information. Passing true for parentUsesSize ensures that this render object will undergo layout if the child undergoes layout. Otherwise, the child can change its layout information without informing this render object.

Implementation

@override
void performLayout() {
  final double desiredWidth = width ?? constraints.maxWidth;
  final double desiredHeight = height ?? constraints.maxHeight;

  // Create a new HTML image element
  imageElement = html.ImageElement();

  // Set the loading listener to update the layout once the image is loaded

  // Set the image dimensions
  imageElement!.src = src;
  imageElement!.width = desiredWidth.toInt();
  imageElement!.height = desiredHeight.toInt();
  final String objectFit = _convertBoxFitToCss(fit);
  imageElement!.style.objectFit = objectFit;

  if (borderRadius != null) {
    final String borderRadiusCss = _convertBorderRadiusToCss(borderRadius!);
    imageElement!.style.borderRadius = borderRadiusCss;
  }

  // Update the size constraints
  size = constraints.constrain(Size(desiredWidth, desiredHeight));
}