insertAndLayoutLeadingChild method

  1. @override
RenderBox? insertAndLayoutLeadingChild(
  1. BoxConstraints childConstraints, {
  2. bool parentUsesSize = false,
})
override

Called during layout to create, add, and layout the child before firstChild.

Calls RenderSliverBoxChildManager.createChild to actually create and add the child if necessary. The child may instead be obtained from a cache; see SliverMultiBoxAdaptorParentData.keepAlive.

Returns the new child or null if no child was obtained.

The child that was previously the first child, as well as any subsequent children, may be removed by this call if they have not yet been laid out during this layout pass. No child should be added during that call except for the one that is created and returned by createChild.

Implementation

@override
RenderBox? insertAndLayoutLeadingChild(
  BoxConstraints childConstraints, {
  bool parentUsesSize = false,
}) {
  final child = super.insertAndLayoutLeadingChild(
    childConstraints,
    parentUsesSize: parentUsesSize,
  );
  if (child != null) {
    final parentData = _getParentData(child);
    parentData.crossAxisIndex = _previousCrossAxisIndexes.isNotEmpty
        ? _previousCrossAxisIndexes.removeLast()
        : 0;
    parentData.lastMainAxisExtent = _previousMainAxisExtents.isNotEmpty
        ? _previousMainAxisExtents.removeLast()
        : 0;
  }

  return child;
}