Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 937b5a2

Browse files
committed
Stack squishes positioned elements near the edge
When laying out positioned children inside a stack, we should give them unbounded constraints because if they draw outside of the stack, we'll just clip them.
1 parent 26203b6 commit 937b5a2

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

examples/widgets/card_collection.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class CardCollectionApp extends App {
7676
// background (text and icons) will just be clipped, not resized.
7777
Widget background = new Positioned(
7878
top: 0.0,
79+
right: 0.0,
80+
bottom: 0.0,
7981
left: 0.0,
8082
child: new Container(
8183
margin: const EdgeDims.all(4.0),

sky/packages/sky/lib/rendering/stack.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,29 +146,19 @@ class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
146146
assert(size.width == constraints.constrainWidth(width));
147147
assert(size.height == constraints.constrainHeight(height));
148148

149-
BoxConstraints innerConstraints = new BoxConstraints.loose(size);
150-
151149
child = firstChild;
152150
while (child != null) {
153151
assert(child.parentData is StackParentData);
154152
final StackParentData childData = child.parentData;
155153

156154
if (childData.isPositioned) {
157-
BoxConstraints childConstraints = innerConstraints;
155+
BoxConstraints childConstraints = const BoxConstraints();
158156

159157
if (childData.left != null && childData.right != null)
160158
childConstraints = childConstraints.applyWidth(size.width - childData.right - childData.left);
161-
else if (childData.left != null)
162-
childConstraints = childConstraints.applyMaxWidth(size.width - childData.left);
163-
else if (childData.right != null)
164-
childConstraints = childConstraints.applyMaxWidth(size.width - childData.right);
165159

166160
if (childData.top != null && childData.bottom != null)
167161
childConstraints = childConstraints.applyHeight(size.height - childData.bottom - childData.top);
168-
else if (childData.top != null)
169-
childConstraints = childConstraints.applyMaxHeight(size.height - childData.top);
170-
else if (childData.bottom != null)
171-
childConstraints = childConstraints.applyMaxHeight(size.width - childData.bottom);
172162

173163
child.layout(childConstraints, parentUsesSize: true);
174164

0 commit comments

Comments
 (0)