BoxyChild
To lay out child widgets we first grab a BoxyChild instance, call layout, and optionally position it.
@override
Size layout() {
// Find our children, in this case we assume there is exactly one
final BoxyChild child = children.single;
// Call layout on the child to obtain their size, we just pass the
// constraints given to the CustomBoxy by its parent
final Size size = child.layout(constraints);
// Optionally position the child
child.position(Offset.zero);
// Return a size
return size;
}
BoxyChild is just a fancy wrapper around RenderBox, it has a bunch of methods and properties that are useful for layout:
- layout, a method that lays out the child given some constraints
- layoutFit, a method that lays out and transforms the child according to a Rect and BoxFit, just like a FittedBox
- layoutRect, a method that lays out and positions the child so that it fits a Rect with an optional alignment property that behaves like an Align
- position, a method that sets the offset of the child
- setTransform, a more advanced version of position that takes a Matrix4 transform
- size, the size of the child after it's laid out
- context, the Element (aka BuildContext) of the child
- id, the id of the child which is provided by either BoxyId or an incrementing integer