layout method

  1. @override
void layout(
  1. Context context,
  2. BoxConstraints constraints, {
  3. bool parentUsesSize = false,
})
override

First widget pass to calculate the children layout and bounding box

Implementation

@override
void layout(Context context, BoxConstraints constraints,
    {bool parentUsesSize = false}) {
  if (!adjustLayout) {
    return super.layout(context, constraints, parentUsesSize: parentUsesSize);
  }

  if (child != null) {
    child!.layout(
      context,
      unconstrained ? const BoxConstraints() : constraints,
      parentUsesSize: parentUsesSize,
    );
    assert(child!.box != null);

    final mat = transform;
    final values = mat.applyToVector3Array(<double>[
      child!.box!.left,
      child!.box!.top,
      0,
      child!.box!.right,
      child!.box!.top,
      0,
      child!.box!.right,
      child!.box!.bottom,
      0,
      child!.box!.left,
      child!.box!.bottom,
      0,
    ]);

    final dx = -math.min(
        math.min(math.min(values[0], values[3]), values[6]), values[9]);
    final dy = -math.min(
        math.min(math.min(values[1], values[4]), values[7]), values[10]);

    box = PdfRect.fromLTRB(
      0,
      0,
      math.max(math.max(math.max(values[0], values[3]), values[6]),
              values[9]) +
          dx,
      math.max(math.max(math.max(values[1], values[4]), values[7]),
              values[10]) +
          dy,
    );

    transform.leftTranslate(dx, dy);
  } else {
    box = PdfRect.fromPoints(PdfPoint.zero, constraints.smallest);
  }
}