Fix empty Stack with infinite constraints throws (#102642)

This commit is contained in:
Bruno Leroux 2022-05-07 13:34:06 +02:00 committed by GitHub
parent ae7fcc7e51
commit c18097178c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -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;

View File

@ -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
}