MultiChildLayoutDelegate class

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.

Each child must be wrapped in a LayoutId widget to assign the id that identifies it to the delegate. The needs to be unique among the children that the CustomMultiChildLayout manages.

Below is an example implementation of performLayout that causes one widget (the follower) to be the same size as another (the leader):
// Define your own slot numbers, depending upon the id assigned by LayoutId.
// Typical usage is to define an enum like the one below, and use those
// values as the ids.
enum _Slot {

class FollowTheLeader extends MultiChildLayoutDelegate {
  void performLayout(Size size) {
    Size leaderSize =;

    if (hasChild(_Slot.leader)) {
      leaderSize = layoutChild(_Slot.leader, BoxConstraints.loose(size));

    if (hasChild(_Slot.follower)) {
      layoutChild(_Slot.follower, BoxConstraints.tight(leaderSize));
      positionChild(_Slot.follower, Offset(size.width - leaderSize.width,
          size.height - leaderSize.height));

  bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) => false;

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.




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


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(covariant 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. [...]


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