Unverified Commit 786d0306 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Assert for RenderFlex intrinsics if using baseline alignment (#70139)

parent fb28ee28
......@@ -512,6 +512,16 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
required double extent, // the extent in the direction that isn't the sizing direction
required _ChildSizingFunction childSize, // a method to find the size in the sizing direction
}) {
if (crossAxisAlignment == CrossAxisAlignment.baseline) {
// Intrinsics cannot be calculated without a full layout for
// baseline alignment. Throw an assertion and return 0.0 as documented
// on [RenderBox.computeMinIntrinsicWidth].
assert(
RenderObject.debugCheckingIntrinsics,
'Intrinsics are not available for CrossAxisAlignment.baseline.'
);
return 0.0;
}
if (_direction == sizingDirection) {
// INTRINSIC MAIN SIZE
// Intrinsic main size is the smallest size the flex container can take
......
......@@ -606,4 +606,30 @@ void main() {
expect(box2.size, const Size(100.0, 100.0));
expect(box3.size, const Size(100.0, 100.0));
});
test('Intrinsics throw if alignment is baseline', () {
final RenderDecoratedBox box = RenderDecoratedBox(
decoration: const BoxDecoration(),
);
final RenderFlex flex = RenderFlex(
textDirection: TextDirection.ltr,
children: <RenderBox>[box],
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
);
layout(flex, constraints: const BoxConstraints(
minWidth: 200.0, maxWidth: 200.0, minHeight: 200.0, maxHeight: 200.0,
));
final Matcher cannotCalculateIntrinsics = throwsA(isAssertionError.having(
(AssertionError e) => e.message,
'message',
'Intrinsics are not available for CrossAxisAlignment.baseline.',
));
expect(() => flex.getMaxIntrinsicHeight(100), cannotCalculateIntrinsics);
expect(() => flex.getMinIntrinsicHeight(100), cannotCalculateIntrinsics);
expect(() => flex.getMaxIntrinsicWidth(100), cannotCalculateIntrinsics);
expect(() => flex.getMinIntrinsicWidth(100), cannotCalculateIntrinsics);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment