insertAndLayoutChild method

  1. @protected
RenderBox? insertAndLayoutChild(
  1. BoxConstraints childConstraints, {
  2. required RenderBox? after,
  3. bool parentUsesSize = false,
})

Called during layout to create, add, and layout the child after the given child.

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. It is the responsibility of the caller to configure the child's scroll offset.

Children after the after child may be removed in the process. Only the new child may be added.

Implementation

@protected
RenderBox? insertAndLayoutChild(
  BoxConstraints childConstraints, {
  required RenderBox? after,
  bool parentUsesSize = false,
}) {
  assert(_debugAssertChildListLocked());
  assert(after != null);
  final int index = indexOf(after!) + 1;
  _createOrObtainChild(index, after: after);
  final RenderBox? child = childAfter(after);
  if (child != null && indexOf(child) == index) {
    child.layout(childConstraints, parentUsesSize: parentUsesSize);
    return child;
  }
  childManager.setDidUnderflow(true);
  return null;
}