Unverified Commit ceca634e authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Constrain width/hight when asking child for intrinsics (#71880)

parent 53119af1
...@@ -234,7 +234,7 @@ class RenderConstrainedBox extends RenderProxyBox { ...@@ -234,7 +234,7 @@ class RenderConstrainedBox extends RenderProxyBox {
double computeMinIntrinsicWidth(double height) { double computeMinIntrinsicWidth(double height) {
if (_additionalConstraints.hasBoundedWidth && _additionalConstraints.hasTightWidth) if (_additionalConstraints.hasBoundedWidth && _additionalConstraints.hasTightWidth)
return _additionalConstraints.minWidth; return _additionalConstraints.minWidth;
final double width = super.computeMinIntrinsicWidth(height); final double width = super.computeMinIntrinsicWidth(_additionalConstraints.constrainHeight(height));
assert(width.isFinite); assert(width.isFinite);
if (!_additionalConstraints.hasInfiniteWidth) if (!_additionalConstraints.hasInfiniteWidth)
return _additionalConstraints.constrainWidth(width); return _additionalConstraints.constrainWidth(width);
...@@ -245,7 +245,7 @@ class RenderConstrainedBox extends RenderProxyBox { ...@@ -245,7 +245,7 @@ class RenderConstrainedBox extends RenderProxyBox {
double computeMaxIntrinsicWidth(double height) { double computeMaxIntrinsicWidth(double height) {
if (_additionalConstraints.hasBoundedWidth && _additionalConstraints.hasTightWidth) if (_additionalConstraints.hasBoundedWidth && _additionalConstraints.hasTightWidth)
return _additionalConstraints.minWidth; return _additionalConstraints.minWidth;
final double width = super.computeMaxIntrinsicWidth(height); final double width = super.computeMaxIntrinsicWidth(_additionalConstraints.constrainHeight(height));
assert(width.isFinite); assert(width.isFinite);
if (!_additionalConstraints.hasInfiniteWidth) if (!_additionalConstraints.hasInfiniteWidth)
return _additionalConstraints.constrainWidth(width); return _additionalConstraints.constrainWidth(width);
...@@ -256,7 +256,7 @@ class RenderConstrainedBox extends RenderProxyBox { ...@@ -256,7 +256,7 @@ class RenderConstrainedBox extends RenderProxyBox {
double computeMinIntrinsicHeight(double width) { double computeMinIntrinsicHeight(double width) {
if (_additionalConstraints.hasBoundedHeight && _additionalConstraints.hasTightHeight) if (_additionalConstraints.hasBoundedHeight && _additionalConstraints.hasTightHeight)
return _additionalConstraints.minHeight; return _additionalConstraints.minHeight;
final double height = super.computeMinIntrinsicHeight(width); final double height = super.computeMinIntrinsicHeight(_additionalConstraints.constrainWidth(width));
assert(height.isFinite); assert(height.isFinite);
if (!_additionalConstraints.hasInfiniteHeight) if (!_additionalConstraints.hasInfiniteHeight)
return _additionalConstraints.constrainHeight(height); return _additionalConstraints.constrainHeight(height);
...@@ -267,7 +267,7 @@ class RenderConstrainedBox extends RenderProxyBox { ...@@ -267,7 +267,7 @@ class RenderConstrainedBox extends RenderProxyBox {
double computeMaxIntrinsicHeight(double width) { double computeMaxIntrinsicHeight(double width) {
if (_additionalConstraints.hasBoundedHeight && _additionalConstraints.hasTightHeight) if (_additionalConstraints.hasBoundedHeight && _additionalConstraints.hasTightHeight)
return _additionalConstraints.minHeight; return _additionalConstraints.minHeight;
final double height = super.computeMaxIntrinsicHeight(width); final double height = super.computeMaxIntrinsicHeight(_additionalConstraints.constrainWidth(width));
assert(height.isFinite); assert(height.isFinite);
if (!_additionalConstraints.hasInfiniteHeight) if (!_additionalConstraints.hasInfiniteHeight)
return _additionalConstraints.constrainHeight(height); return _additionalConstraints.constrainHeight(height);
......
...@@ -190,4 +190,23 @@ void main() { ...@@ -190,4 +190,23 @@ void main() {
); );
expect(patient.currentContext!.size, equals(const Size(0.0, 0.0))); expect(patient.currentContext!.size, equals(const Size(0.0, 0.0)));
}); });
testWidgets('SizedBox constrains intrinsics', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/27293.
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: IntrinsicHeight(
child: SizedBox(
width: 100,
child: Text('This is a multi-line text.', style: TextStyle(height: 1.0, fontSize: 16)),
),
),
),
),
);
expect(tester.getSize(find.text('This is a multi-line text.')).height, greaterThan(16));
});
} }
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