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}) {
  final size = constraints.biggest;

  var maxWidth = 0.0;
  var maxHeight = 0.0;
  PdfPoint? first;
  PdfPoint? last;

  for (final value in values) {
    last = Widget.measure(_text(value), context: context);
    maxWidth = math.max(maxWidth, last.x);
    maxHeight = math.max(maxHeight, last.y);
    first ??= last;
  }

  final ad = _angleDirection();

  switch (direction) {
    case Axis.horizontal:
      _textMargin = margin ?? 2;
      _axisTick ??= false;
      final minStart = ad == 0 ? first!.x / 2 : (ad > 0 ? first!.x : 0.0);
      _marginEnd = math.max(
          _marginEnd, ad == 0 ? last!.x / 2 : (ad > 0 ? 0.0 : last!.x));
      crossAxisPosition = math.max(crossAxisPosition, minStart);
      axisPosition = math.max(axisPosition, maxHeight + _textMargin);
      box = PdfRect(0, 0, size.x, axisPosition);
      break;
    case Axis.vertical:
      _textMargin = margin ?? 10;
      _axisTick ??= true;
      _marginEnd = math.max(
          _marginEnd, ad == 0 ? last!.x / 2 : (ad < 0 ? last!.x : 0.0));
      final minStart = ad == 0 ? first!.y / 2 : (ad > 0 ? first!.x : 0.0);
      crossAxisPosition = math.max(crossAxisPosition, minStart);
      axisPosition = math.max(axisPosition, maxWidth + _textMargin);
      box = PdfRect(0, 0, axisPosition, size.y);
      break;
  }
}