setChild method Null safety

void setChild(
  1. int x,
  2. int y,
  3. RenderBox? value
)

Replaces the child at the given position with the given child.

If the given child is already located at the given position, this function does not modify the table. Otherwise, the given child must not already have a parent.

Implementation

void setChild(int x, int y, RenderBox? value) {
  assert(x != null);
  assert(y != null);
  assert(x >= 0 && x < columns && y >= 0 && y < rows);
  assert(_children.length == rows * columns);
  final int xy = x + y * columns;
  final RenderBox? oldChild = _children[xy];
  if (oldChild == value) {
    return;
  }
  if (oldChild != null) {
    dropChild(oldChild);
  }
  _children[xy] = value;
  if (value != null) {
    adoptChild(value);
  }
}