Assert for RenderFlex intrinsics if using baseline alignment (#70139)
This commit is contained in:
parent
fb28ee2860
commit
786d0306db
@ -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 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
|
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) {
|
if (_direction == sizingDirection) {
|
||||||
// INTRINSIC MAIN SIZE
|
// INTRINSIC MAIN SIZE
|
||||||
// Intrinsic main size is the smallest size the flex container can take
|
// 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(box2.size, const Size(100.0, 100.0));
|
||||||
expect(box3.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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user