layoutPositionedChild static method
Lays out the positioned child according to alignment within a Stack of size.
Returns true when the child has visual overflow.
Implementation
static bool layoutPositionedChild(RenderBox child, BoxData childParentData,
Size size, Alignment alignment) {
assert(childParentData.isPositioned);
assert(child.parentData == childParentData);
var position = childParentData.position;
bool hasVisualOverflow = false;
BoxConstraints childConstraints = const BoxConstraints();
if (position.left != null && position.right != null) {
childConstraints = childConstraints.tighten(
width: size.width - position.right! - position.left!);
}
else if (size.width.isFinite) {
childConstraints = BoxConstraints(
minWidth: childConstraints.minWidth,
maxWidth: size.width,
minHeight: childConstraints.minHeight,
maxHeight: childConstraints.maxHeight);
}
if (position.top != null && position.bottom != null) {
childConstraints = childConstraints.tighten(
height: size.height - position.bottom! - position.top!);
}
else if (size.height.isFinite) {
childConstraints = BoxConstraints(
minWidth: childConstraints.minWidth,
maxWidth: childConstraints.maxWidth,
minHeight: childConstraints.minHeight,
maxHeight: size.height);
}
// calculate the child's size by performing
// a dry layout. We use LocalBoxConstraints in order to
// override isTight, which is used in Layout() to determine if a
// child size change forces a parent to resize.
child.layout(LocalBoxConstraints.from(childConstraints),
parentUsesSize: true);
final double x;
if (position.left != null) {
x = position.left!;
} else if (position.right != null) {
x = size.width - position.right! - child.size.width;
} else {
x = alignment.alongOffset(size - child.size as Offset).dx;
}
if (x < 0.0 || x + child.size.width > size.width) {
hasVisualOverflow = true;
}
final double y;
if (position.top != null) {
y = position.top!;
} else if (position.bottom != null) {
y = size.height - position.bottom! - child.size.height;
} else {
y = alignment.alongOffset(size - child.size as Offset).dy;
}
if (y < 0.0 || y + child.size.height > size.height) {
hasVisualOverflow = true;
}
childParentData.offset = Offset(x, y);
return hasVisualOverflow;
}