applyParentData method

  1. @override
void applyParentData(
  1. RenderObject renderObject
)
override

Write the data from this widget into the given render object's parent data.

The framework calls this function whenever it detects that the RenderObject associated with the child has outdated RenderObject.parentData. For example, if the render object was recently inserted into the render tree, the render object's parent data might not match the data in this widget.

Subclasses are expected to override this function to copy data from their fields into the RenderObject.parentData field of the given render object. The render object's parent is guaranteed to have been created by a widget of type T, which usually means that this function can assume that the render object's parent data object inherits from a particular class.

If this function modifies data that can change the parent's layout or painting, this function is responsible for calling RenderObject.markNeedsLayout or RenderObject.markNeedsPaint on the parent, as appropriate.

Implementation

@override
void applyParentData(RenderObject renderObject) {
  assert(renderObject.parentData is GridParentData);
  final parentData = renderObject.parentData as GridParentData;
  bool needsLayout = false;

  // TODO(shyndman): I don't like that we clear out a field that another
  // placement widget uses. We should probably enter a mode specific to this
  // placement widget, and have the ParentData figure out its internal state.
  if (parentData.areaName != null) {
    parentData.areaName = null;
    needsLayout = true;
  }

  if (parentData.columnStart != columnStart) {
    parentData.columnStart = columnStart;
    needsLayout = true;
  }

  if (parentData.columnSpan != columnSpan) {
    parentData.columnSpan = columnSpan;
    needsLayout = true;
  }

  if (parentData.rowStart != rowStart) {
    parentData.rowStart = rowStart;
    needsLayout = true;
  }

  if (parentData.rowSpan != rowSpan) {
    parentData.rowSpan = rowSpan;
    needsLayout = true;
  }

  if (needsLayout) {
    final AbstractNode? targetParent = renderObject.parent;
    if (targetParent is RenderLayoutGrid) targetParent.markNeedsPlacement();
    if (targetParent is RenderObject) targetParent.markNeedsLayout();
  }
}