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() {
  assert(childCount == 2);
  _stickyContentBody?.layout(constraints.loosen(), parentUsesSize: true);
  _contentBody?.layout(constraints.loosen(), parentUsesSize: true);
  final stickyContentBodyHeight = _stickyContentBody!.size.height;
  final contentBodyHeight = _contentBody!.size.height;
  final height = max(
      constraints.minHeight,
      _enableHeaderOverlap
          ? contentBodyHeight
          : stickyContentBodyHeight + contentBodyHeight);
  final width = max(constraints.minWidth, contentBodyHeight);

  size = Size(
      constraints.constrainWidth(width), constraints.constrainHeight(height));
  final double stickyContentBodyOffset = getHeaderTileStuckOffset();

  double crossSize = 0;
  double allottedSize = 0;
  RenderBox? child = firstChild;
  while (child != null) {
    // ignore: avoid_as
    final FlexParentData? childParentData =
        // ignore: avoid_as
        child.parentData as FlexParentData?;
    final int flex = _getFlex(child);
    if (flex > 0) {
    } else {
      late BoxConstraints innerConstraints;
      switch (_direction) {
        case Axis.horizontal:
          innerConstraints = BoxConstraints(maxHeight: constraints.maxHeight);
          break;
        case Axis.vertical:
          innerConstraints = BoxConstraints(maxWidth: constraints.maxWidth);
          break;
      }
      child.layout(innerConstraints, parentUsesSize: true);
      allottedSize += _getMainSize(child);
      crossSize = math.max(crossSize, _getCrossSize(child));
    }
    assert(child.parentData == childParentData);
    child = childParentData?.nextSibling;
  }

  final double idealSize = allottedSize;
  late double actualSize;
  switch (_direction) {
    case Axis.horizontal:
      size = constraints.constrain(Size(idealSize, crossSize));
      actualSize = size.width;
      crossSize = size.height;
      break;
    case Axis.vertical:
      size = constraints.constrain(Size(crossSize, idealSize));
      actualSize = size.height;
      crossSize = size.width;
      break;
  }
  const double startingSpace = 0;
  const double betweenSpace = 0;
  const bool flipMainAxis = !true;
  double childMainPosition =
      // ignore: dead_code
      flipMainAxis ? actualSize - startingSpace : startingSpace;
  child = _contentBody;
  // ignore: invariant_booleans
  while (child != null) {
    // ignore: avoid_as
    final FlexParentData? childParentData =
        // ignore: avoid_as
        child.parentData as FlexParentData?;

    // if (flipMainAxis) {
    //   childMainPosition = _getMainSize(child);
    // }
    switch (_direction) {
      case Axis.horizontal:
        final FlexParentData contentBodyParentData =
            // ignore: avoid_as
            _contentBody!.parentData as FlexParentData;
        contentBodyParentData.offset =
            _stickyContentPosition == GFPosition.start
                ? Offset(_stickyContentBody!.size.width, 0)
                : const Offset(0, 0);
        final FlexParentData stickyContentBodyParentData =
            // ignore: avoid_as
            _stickyContentBody!.parentData as FlexParentData;
        stickyContentBodyParentData.offset = Offset(
            childMainPosition,
            max(
                min(-stickyContentBodyOffset,
                    height - stickyContentBodyHeight),
                0));
        break;
      case Axis.vertical:
        final FlexParentData contentBodyParentData =
            // ignore: avoid_as
            _contentBody!.parentData as FlexParentData;
        contentBodyParentData.offset =
            Offset(0, _enableHeaderOverlap ? 0.0 : stickyContentBodyHeight);
        final FlexParentData stickyContentBodyParentData =
            // ignore: avoid_as
            _stickyContentBody!.parentData as FlexParentData;
        stickyContentBodyParentData.offset = Offset(
            0,
            max(
                0,
                min(-stickyContentBodyOffset,
                    height - stickyContentBodyHeight)));
        break;
    }
    if (_callback != null) {
      final stuckValue = max(
              min(stickyContentBodyHeight, stickyContentBodyOffset),
              -stickyContentBodyHeight) /
          stickyContentBodyHeight;
      _callback!(stuckValue);
    }
    // if (flipMainAxis) {
    //   childMainPosition -= betweenSpace;
    // }
    if (!flipMainAxis) {
      childMainPosition += _getMainSize(child) + betweenSpace;
    }
    child = childParentData!.nextSibling;
  }
}