A delegate that controls the layout of multiple children.

Delegates must be idempotent. Specifically, if two delegates are equal, then they must produce the same layout. To change the layout, replace the delegate with a different instance whose shouldRelayout returns true when given the previous instance.

Override getSize to control the overall size of the layout. The size of the layout cannot depend on layout properties of the children.

Override performLayout to size and position the children. An implementation of performLayout must call layoutChild exactly once for each child, but it may call layoutChild on children in an arbitrary order. Typically a delegate will use the size returned from layoutChild on one child to determine the constraints for performLayout on another child or to determine the offset for positionChild for that child or another child.

Override shouldRelayout to determine when the layout of the children needs to be recomputed when the delegate changes.

Used with CustomMultiChildLayout, the widget for the RenderCustomMultiChildLayoutBox render object.

Example

Below is an example implementation of performLayout that causes one widget to be the same size as another:

@override
void performLayout(Size size) {
  Size followerSize = Size.zero;

  if (hasChild(_Slots.leader) {
    followerSize = layoutChild(_Slots.leader, new BoxConstraints.loose(size));
    positionChild(_Slots.leader, Offset.zero);
  }

  if (hasChild(_Slots.follower)) {
    layoutChild(_Slots.follower, new BoxConstraints.tight(followerSize));
    positionChild(_Slots.follower, new Offset(size.width - followerSize.width,
                                              size.height - followerSize.height));
  }
}

The delegate gives the leader widget loose constraints, which means the child determines what size to be (subject to fitting within the given size). The delegate then remembers the size of that child and places it in the upper left corner.

The delegate then gives the follower widget tight constraints, forcing it to match the size of the leader widget. The delegate then places the follower widget in the bottom right corner.

The leader and follower widget will paint in the order they appear in the child list, regardless of the order in which layoutChild is called on them.

Constructors

MultiChildLayoutDelegate()

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

getSize(BoxConstraints constraints) Size
Override this method to return the size of this object given the incoming constraints. [...]
hasChild(Object childId) bool
True if a non-null LayoutChild was provided for the specified id. [...]
layoutChild(Object childId, BoxConstraints constraints) Size
Ask the child to update its layout within the limits specified by the constraints parameter. The child's size is returned. [...]
performLayout(Size size) → void
Override this method to lay out and position all children given this widget's size. [...]
positionChild(Object childId, Offset offset) → void
Specify the child's origin relative to this origin. [...]
shouldRelayout(MultiChildLayoutDelegate oldDelegate) bool
Override this method to return true when the children need to be laid out. [...]
toString() String
Override this method to include additional information in the debugging data printed by debugDumpRenderTree and friends. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(other) bool
The equality operator. [...]
inherited