addInitialChild method

  1. @protected
bool addInitialChild(
  1. {int index = 0,
  2. double layoutOffset = 0.0}

Called during layout to create and add the child with the given index and scroll offset.

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 false if there was no cached child and createChild did not add any child, otherwise returns true.

Does not layout the new child.

When this is called, there are no visible children, so no children can be removed during the call to createChild. No child should be added during that call either, except for the one that is created and returned by createChild.


bool addInitialChild({ int index = 0, double layoutOffset = 0.0 }) {
  assert(firstChild == null);
  _createOrObtainChild(index, after: null);
  if (firstChild != null) {
    assert(firstChild == lastChild);
    assert(indexOf(firstChild!) == index);
    final SliverMultiBoxAdaptorParentData firstChildParentData = firstChild!.parentData! as SliverMultiBoxAdaptorParentData;
    firstChildParentData.layoutOffset = layoutOffset;
    return true;
  return false;