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

Commit c180971

Browse files
authored
Fix empty Stack with infinite constraints throws (#102642)
1 parent ae7fcc7 commit c180971

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/flutter/lib/src/rendering/stack.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,7 @@ class RenderStack extends RenderBox
520520
assert(_resolvedAlignment != null);
521521
bool hasNonPositionedChildren = false;
522522
if (childCount == 0) {
523-
assert(constraints.biggest.isFinite);
524-
return constraints.biggest;
523+
return (constraints.biggest.isFinite) ? constraints.biggest : constraints.smallest;
525524
}
526525

527526
double width = constraints.minWidth;

packages/flutter/test/rendering/stack_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,30 @@ void main() {
148148
});
149149
});
150150

151+
test('Stack in Flex can layout with no children', () {
152+
// Render an empty Stack in a Flex
153+
final RenderFlex flex = RenderFlex(
154+
textDirection: TextDirection.ltr,
155+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
156+
children: <RenderBox>[
157+
RenderStack(
158+
textDirection: TextDirection.ltr,
159+
children: <RenderBox>[],
160+
),
161+
]
162+
);
163+
164+
bool stackFlutterErrorThrown = false;
165+
layout(
166+
flex,
167+
constraints: BoxConstraints.tight(const Size(100.0, 100.0)),
168+
onErrors: () {
169+
stackFlutterErrorThrown = true;
170+
}
171+
);
172+
173+
expect(stackFlutterErrorThrown, false);
174+
});
175+
151176
// More tests in ../widgets/stack_test.dart
152177
}

0 commit comments

Comments
 (0)