performLayout method
Override this method to lay out and position all children given this widget's size.
This method must call layoutChild for each child. It should also specify the final position of each child with positionChild.
Implementation
@override
void performLayout(Size size) {
// Layout the centered child
final sizeCentered = layoutChild('centered', BoxConstraints.loose(size));
final centerX = (size.width - sizeCentered.width) / 2;
final centerY = (size.height - sizeCentered.height) / 2;
positionChild('centered', Offset(centerX, centerY));
// Layout the bottom widget if it exists
if (hasChild('bottom')) {
final sizeBottom = layoutChild('bottom', BoxConstraints.loose(size));
positionChild(
'bottom',
Offset((size.width - sizeBottom.width) / 2,
centerY + sizeCentered.height + bottomGap),
);
}
// Layout the top widget if it exists
if (hasChild('top')) {
final sizeTop = layoutChild('top', BoxConstraints.loose(size));
positionChild(
'top',
Offset((size.width - sizeTop.width) / 2,
centerY - sizeTop.height - topGap),
);
}
// Layout the left widget if it exists
if (hasChild('left')) {
final sizeLeft = layoutChild('left', BoxConstraints.loose(size));
positionChild(
'left',
Offset(centerX - sizeLeft.width - leftGap, centerY),
);
}
// Layout the right widget if it exists
if (hasChild('right')) {
positionChild(
'right',
Offset(centerX + sizeCentered.width + rightGap, centerY),
);
}
}