Skip to content

Commit

Permalink
Fix empty Stack with infinite constraints throws (#102642)
Browse files Browse the repository at this point in the history
  • Loading branch information
bleroux authored May 7, 2022
1 parent ae7fcc7 commit c180971
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/flutter/lib/src/rendering/stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ class RenderStack extends RenderBox
assert(_resolvedAlignment != null);
bool hasNonPositionedChildren = false;
if (childCount == 0) {
assert(constraints.biggest.isFinite);
return constraints.biggest;
return (constraints.biggest.isFinite) ? constraints.biggest : constraints.smallest;
}

double width = constraints.minWidth;
Expand Down
25 changes: 25 additions & 0 deletions packages/flutter/test/rendering/stack_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,30 @@ void main() {
});
});

test('Stack in Flex can layout with no children', () {
// Render an empty Stack in a Flex
final RenderFlex flex = RenderFlex(
textDirection: TextDirection.ltr,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <RenderBox>[
RenderStack(
textDirection: TextDirection.ltr,
children: <RenderBox>[],
),
]
);

bool stackFlutterErrorThrown = false;
layout(
flex,
constraints: BoxConstraints.tight(const Size(100.0, 100.0)),
onErrors: () {
stackFlutterErrorThrown = true;
}
);

expect(stackFlutterErrorThrown, false);
});

// More tests in ../widgets/stack_test.dart
}

0 comments on commit c180971

Please sign in to comment.